[JavaScript] 纯文本查看 复制代码
[
{ "id":"11", "pId":"0", "name":"基础数据"},
{ "id":"111", "pId":"11", "name":"基础档案设置", "page":"pages/base/archives.html"},
{ "id":"112", "pId":"11", "name":"收派标准", "page":"pages/base/standard.html"},
{ "id":"113", "pId":"11", "name":"班车管理", "page":"pages/base/vehicle.html"},
{ "id":"114", "pId":"11", "name":"快递员设置/替班", "page":"pages/base/courier.html"},
{ "id":"115", "pId":"11", "name":"区域设置","page":"pages/base/area.html"},
{ "id":"116", "pId":"11", "name":"管理分区", "page":"pages/base/sub_area.html"},
{ "id":"117", "pId":"11", "name":"管理定区/调度排班","page":"pages/base/fixed_area.html"},
{ "id":"118", "pId":"11", "name":"收派时间管理","page":"pages/base/take_time.html"},
{ "id":"12", "pId":"0", "name":"受理"},
{ "id":"121", "pId":"12", "name":"业务受理" ,"page":"pages/take_delivery/order.html"},
{ "id":"122", "pId":"12", "name":"运单快速录入" ,"page":"pages/take_delivery/waybill_quick.html"},
{ "id":"123", "pId":"12", "name":"运单录入" ,"page":"pages/take_delivery/waybill.html"},
{ "id":"124", "pId":"12", "name":"运单导入" ,"page":"pages/take_delivery/waybill_import.html"},
{ "id":"125", "pId":"12", "name":"运单管理" ,"page":"pages/take_delivery/waybill_manage.html"},
{ "id":"126", "pId":"12", "name":"异调运单" ,"page":"pages/take_delivery/different_waybill.html"},
{ "id":"127", "pId":"12", "name":"运单打印" ,"page":"pages/take_delivery/waybill_print.html"}
]
[JavaScript] 纯文本查看 复制代码
//定义全局变量,做为zTree对象
var treeObj;
$(function(){
// 树初始化
var setting = {
data : {
//支持简单数据格式
simpleData : {
enable : true
}
},
//支持被选择
check : {
enable : true
}
};
//初始化菜单树。注意,此处用的是text方式接受的数据
$.ajax({
url : '../js/menu.json',
type : 'POST',
dataType : 'text',
success : function(data) {
var zNodes = eval("(" + data + ")");//将text格式数据转成json数据。必须带小括号
console.log(zNodes);//打印JSON数据信息
treeObj = $.fn.zTree.init($("#zTreeId"), setting, zNodes);//初始化zTree
},
error : function(msg) {
alert('树加载异常!');
}
});
});
[JavaScript] 纯文本查看 复制代码
[
{ "id":"111", "pId":"11", "name":"基础档案设置", "page":"pages/base/archives.html"},
{ "id":"112", "pId":"11", "name":"收派标准", "page":"pages/base/standard.html"},
{ "id":"113", "pId":"11", "name":"班车管理", "page":"pages/base/vehicle.html"},
{ "id":"121", "pId":"12", "name":"业务受理" ,"page":"pages/take_delivery/order.html"}
]
[JavaScript] 纯文本查看 复制代码
function editZTree(){
//获取可以被勾选的数据
var checkedData;
$.ajax({
url : '../js/checked.json',
type : 'POST',
dataType : 'json',
async:false, //一定要使用同步请求,否则,下面的checkedData在遍历取值的时候可能(或一定)获取不到数据
success : function(data) {
checkedData = data;
},
error : function(msg) {
alert('异常!');
}
});
//遍历获取的数据,赋值到zTree上做勾选
for(var i = 0; i < checkedData.length; i ++){
var node = treeObj.getNodeByParam("id", checkedData.id, null);//根据属性名和属性值确定节点
treeObj.checkNode(node, true, true);//选取该节点,并设定父子互动
}
}