现有全省各地区静态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
。
最新评论
网飞没问题, 迪士尼+有解决方案么?
pp助手是安卓手机用的,根本下载用不来苹果
已解决
这样的话数据库里的结构为{"attachment":{"content":"xxx"}}, 要怎么才能变成{"content":"xxx"},从而使结构保持一致?
赞! make test不过的坑都写到的,谢谢楼主~
谢谢你
用了root用户还是一直502是怎么回事呢
student id 是空的