ztree報init錯怎么改?
<script type="text/javascript">
var setting = {
callback: {
onClick: zTreeOnClick,
onCheck: zTreeOnCheck
},
check: {
enable: true,
chkStyle: "radio",
radioType: "level"
},
view: {
showLine: false
},
data: {
simpleData: {
enable: true
}
}
};
//var setting = {
// check: {
// enable: true,
// chkStyle: "radio",
// radioType: "all",
// },
// data: {
// simpleData: {
// enable: true
// }
// },
// view: {
// showLine: false
// },
// callback: {
// onClick: zTreeOnClick,
// onCheck: zTreeOnCheck,
// }
//};
//點擊節點事件
//點擊節點選中單選框
function zTreeOnClick(event, treeId, treeNode) {
$("#ArticlesCategoryId").val(treeNode.id);
$("#ArticlesCategorytext").val(treeNode.name);
//alert(treeNode.tId + ", " + treeNode.name + "," + treeNode.checked);
var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
var nodes = treeObj.getSelectedNodes();
for (var i = 0, l = nodes.length; i < l; i++) {
treeObj.checkNode(nodes[i], "",true, true);
}
//判斷如果取消選中節點 還有沒有選中的節點, 如果沒有選中取消的節點
var nodes = treeObj.getCheckedNodes(true);
if (nodes.length <= 0)
{
var nodes = treeObj.getSelectedNodes();
for (var i = 0, l = nodes.length; i < l; i++) {
treeObj.checkNode(nodes[i], "", true, true);
}
}
}
//點擊單選框事件
function zTreeOnCheck(event, treeId, treeNode) {
//alert(treeNode.tId + ", " + treeNode.name + "," + treeNode.id);
$("#ArticlesCategoryId").val(treeNode.id);
$("#ArticlesCategorytext").val(treeNode.name);
//判斷如果取消選中節點 還有沒有選中的節點, 如果沒有選中取消的節點
var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
var nodes = treeObj.getCheckedNodes(true);
if (nodes.length <= 0)
{
treeObj.checkNode(treeObj.getNodeByParam("id", treeNode.id, null), "", true, true);
}
}
zNodes = [
<% = NodesData %>
];
var code;
function setCheck() {
var type = $("#level").attr("checked") ? "level" : "all";
setting.check.radioType = type;
showCode('setting.check.radioType = "' + type + '";');
$.fn.zTree.init($("#treeDemo"), setting, zNodes);
}
function showCode(str) {
if (!code) code = $("#code");
code.empty();
code.append("<li>" + str + "</li>");
}
$(document).ready(function () {
setCheck();
$("#level").bind("change", setCheck);
$("#all").bind("change", setCheck);
var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
var nodes = treeObj.getNodes();
treeObj.checkNode(nodes[0], "",true, true);
treeObj.selectNode(nodes[0])
zTreeOnCheck("", nodes[0].id, nodes[0]);
});
</script>