device-cat-select.js
2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//获取父级分类
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 = "<option value=''>--请选择--</option>";
for(var s in data){
html = html +"<option value='"+data[s]['id']+"'>"+data[s]['name']+"</option>";
}
$("#deviceParentCat").html(html);
//触发二级选择
//$("#deviceParentCat").trigger("change");
}else{
//提示确认失败
alert("加载失败");
}
},
error:function(msg){
//提示确认失败
alert("加载异常");
}
});
}
function loadDeviceCat($dataurl){
var pid = $("#deviceParentCat").val();
if(pid == ""){
$("#deviceChildCat").html("<option value=''>--请选择二级分类--</option>");
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 = "<option value=''>--请选择二级分类--</option>";
var cat_id = $("#hid_cat_id").val();
for(var s in data){
if(parseInt(cat_id) == parseInt(data[s]['id'])){
html = html +"<option value='"+data[s]['id']+"' selected=\"selected\">"+data[s]['name']+"</option>";
}else{
html = html +"<option value='"+data[s]['id']+"'>"+data[s]['name']+"</option>";
}
}
$("#deviceChildCat").html(html);
}else{
alert("加载失败");
}
},
error:function(msg){
//提示确认失败
alert("加载异常");
}
});
}
/* 使用方法
<script src="<?php echo Url::toRoute('/exts-src/base/1.0.0/ui/device-cat-select/device-cat-select.js'); ?>" type="text/javascript" ></script>
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")?>');
});
*/