标签:
代码如下:
<script type="text/javascript">
var reginTree = {
setting: {
view: {
fontCss: {
color: "#000"
}
},
check: {
enable: true,
chkboxType: {
"Y": "p",
"N": "p"
}, //加上ps 当点击父节点时子节点全部选中
children: "children"
},
data: {
key: {
checked: "checked"
},
simpleData: {
enable: true,
idKey: "id",
pIdKey: "pId",
rootPId: 0
}
}
},
//获取ztree对象
getZtreeObj: function(id) {
var zTree;
if ($.fn.zTree.getZTreeObj(id) != null && $.fn.zTree.getZTreeObj(id) != undefined) {
zTree = $.fn.zTree.getZTreeObj(id);
}
return zTree;
},
//初始化ztree
loadZtree: function(json, id, treeNode, callback) {
var setter = $.extend({}, reginTree.setting, json);
$.fn.zTree.init($(‘#‘ + id), setter, treeNode);
var zTree = reginTree.getZtreeObj(id);
if (callback) callback();
},
//加载ztree
loadArea: function() {
var regionJson = {
"level": "2"
};
var treeNode = [];
_public_.getJson(regionJson, "frontServer?busiCode=02060203").done(function(data) {
if (data.returnCode == "Y") {
for (var i = 0; i < data.regionList.length; i++) {
var id = data.regionList[i].rid;
var pId = data.regionList[i].pid;
var name = data.regionList[i].regionName;
var json = {
"id": id,
"name": name,
"pId": pId
};
treeNode.push(json);
}
} else {
console.log("加载数据失败");
}
reginTree.loadZtree({
callback: {
onCheck: reginTree.zTreeOnCheck
}
}, ‘tree‘, treeNode);
});
},
//ztree节点选中
zTreeOnCheck: function(event, treeId, treeNode) {
alert(treeNode.tId + ", " + treeNode.name + "," + treeNode.checked);
}
};
reginTree.loadArea();
</script>
标签:
原文地址:http://www.cnblogs.com/nianzhilian/p/4785751.html