//获取父级分类
function loadParentCat($dataurl){
$.ajax({
type: "post",
url: $dataurl,
dataType:"json",
data: $.csrf({"parentId":0}),
success:function(msg){
if(msg['status'] == 1){
var data = eval(msg['modelList']);
var html = "";
for(var s in data){
html = html +"";
}
$("#deviceParentCat").html(html);
//触发二级选择
//$("#deviceParentCat").trigger("change");
}else{
//提示确认失败
alert("加载失败");
}
},
error:function(msg){
//提示确认失败
alert("加载异常");
}
});
}
function loadDeviceCat($dataurl){
var pid = $("#deviceParentCat").val();
if(pid == ""){
$("#deviceChildCat").html("");
return false;
}
$.ajax({
type: "post",
url: $dataurl,
dataType:"json",
data: $.csrf({"parentId":pid}),
success:function(msg){
if(msg['status'] == 1){
var data = eval(msg['modelList']);
var html = "";
var cat_id = $("#hid_cat_id").val();
for(var s in data){
if(parseInt(cat_id) == parseInt(data[s]['id'])){
html = html +"";
}else{
html = html +"";
}
}
$("#deviceChildCat").html(html);
}else{
alert("加载失败");
}
},
error:function(msg){
//提示确认失败
alert("加载异常");
}
});
}
/* 使用方法
loadParentCat('=Url::toRoute("/device/model/get-device-cat-list")?>');
loadDeviceCat('=Url::toRoute("/device/model/get-device-cat-list")?>');
$("#deviceParentCat").bind("change",function(){
loadDeviceCat('<1?=Url::toRoute("/device/model/get-device-cat-list")?>');
});
*/