在初始加載樹形控件的時候調用zTree的expandNode (node, expandFlag, sonSign, focus, callbackFlag)方法
node:樹形節點
expandFlag:是否展開節點
sonSign:是否展開其子孫節點
focus:展開或折疊節點后是否設置焦點
callbackFlag:這行該方法是否觸發回調函數
var zNodes = "";
var setting = {
check: {
enable: true
},
data: {//數據加載
keep: {
parent: true,
leaf: true
},
simpleData: {
enable: true,
idKey: "Id",
pIdKey: "Pid",
},
key: {
name: "Name"
}
}
};
function Inint() {//初始化加載節點
$.ajax({
global: true,
async: false,
cache: false,
dataType: "json",
url: '../Ajax/test.ashx',
type: "post",
//data: { "roleId": GetQueryString("roleId") },
success: function (data) {
zNodes = data;
}
});
};
$(function () {
Inint(); //加載數據
$.fn.zTree.init($("#zTree"), setting, zNodes);
var treeObj = $.fn.zTree.getZTreeObj("zTree");
var nodes = treeObj.getNodes();
for (var i = 0; i < nodes.length; i++) { //設置節點展開
treeObj.expandNode(nodes[i], true, false, true);
}
});
<div class="control" style="overflow: auto; height:270px;"> <ul id="zTree"> </ul> </div>
