1.控制器返回数据集
echo json_encode($res);die;
[{"id":805,"pid":803,"title":"\u5e7f\u5dde-\u7535\u8bdd\u987e\u95ee1"},{"id":804,"pid":803,"title":"\u5e7f\u5dde-\u7535\u8bdd\u987e\u95ee2"},
2.JS读取
var data1 ;
$.ajax({
url:'{:url('register')}',
type:"post",
data:{action:'js_type',tid:{$tid},cid:{$cid},ccid:{$ccid}},
async:false,
success:function(data){
data1 = JSON.parse(data);
//console.log(data1);
},
error:function(){
layer.msg('读取数据失败!');
}
});
//console.log(data1);
//var data=[{"id":1,"pid":0,"title":"1-1"},{"id":2,"pid":0,"title":"1-2"},{"id":3,"pid":0,"title":"1-3"},{"id":4,"pid":1,"title":"1-1-1"},{"id":5,"pid":1,"title":"1-1-2"},{"id":6,"pid":2,"title":"1-2-1"},{"id":7,"pid":2,"title":"1-2-3"},{"id":8,"pid":3,"title":"1-3-1"},{"id":9,"pid":3,"title":"1-3-2"},{"id":10,"pid":4,"title":"1-1-1-1"},{"id":11,"pid":4,"title":"1-1-1-2"}];
interact.render({
elem : '.test',
title : '选择联动',
data : data1,
name : 'region',
});