现有全省各地区静态JSON数据,现在想通过Url参数,动态控制是否显示复选框/单选框,实现方式如下:
var rootNode, isCascadeSelect = '1';
var urlParamsJson = urlParams();
var selType = urlParamsJson.selType, isChkbox = urlParamsJson.isChkbox;
initTree();
function initTree() {
// 用于存储树的节点
var treeNodes = [];
$.ajax({
url: area_tree_data,
async: false,
dataType: "json",
type: "GET",
success: function (result) {
treeNodes = result;
}
});
// ztree设置
var treeSetting = {
data: {
key: {
name: "name"
},
simpleData: {
enable: true,
idKey: "code",
pIdKey: "pcode"
}
},
check: {
enable: selType ? true : false,
chkStyle: isChkbox == "1" ? "checkbox" : "radio",
radioType: "all",
chkboxType: {"Y": isCascadeSelect == "1" ? "s" : "", "N": isCascadeSelect == "1" ? "s" : ""}
},
callback: {
beforeExpand: zTreeBeforeExpand
}
};
// 初始化功能树
areaTree = ztree.init($("#area-tree"), treeSetting, treeNodes);
rootNode = areaTree.getNodes()[0];
areaTree.expandNode(rootNode, null, null, null, true);
}
function zTreeBeforeExpand(treeId, treeNode) {
if (selType) {
var selectTypes = selType.split(";");
if ($.inArray((treeNode.level + 1).toString(), selectTypes) == "-1") {
treeNode["nocheck"] = true;
areaTree.updateNode(treeNode);
}
$.grep(treeNode.children, function (childNode, index) {
if ($.inArray((childNode.level + 1).toString(), selectTypes) == "-1") {
childNode["nocheck"] = true;
areaTree.updateNode(childNode);
}
});
}
}
页面调用地址:http://localhost:8080/html/portrait/area-tree.html?selType=1;2;3&isChkbox=1
。
最新评论
我的是ipv4网络,如何使用直播源啊!
我今天试了,不想啊,我的是新疆昌吉移动的网络。
收不到验证码电报
现在充值29起了