jstree異步加載 話很少說 直接貼代碼

 

 

 

//也能夠多去試試,不會就找度娘,阿彌陀佛,貧道去也node

//實體類ajax

public class Tree
{
/// <summary>
/// 節點ID
/// </summary>
public string id { get; set; }
/// <summary>
/// 父級id
/// </summary>
public string parent { get; set; }
/// <summary>
/// 內容
/// </summary>
public string text { get; set; }json

//"{\"m_type\":\"g\"}"  能夠根據該參數判斷是節點子級仍是父級或者自定義
public string data { get; set; }ui

//是否有子節點
public bool children { get; set; }
}this

 

$('#tree_rule').jstree({
'core': {
'check_callback': true,
"data": function (obj, callback) {
$.ajax({
type: "get",
url: "數據的地址",//getAreaBuild=getTreeArea
dataType: "json",
'data': { "Phone": phone,"AccptMan": "company" //傳參
},
success: function (data) {
console.info(data);
if (data.length > 0) {
callback.call(this, data);//添加數據
} else {
bootbox.alert("暫無數據!");
}
}
});
}
},
'plugins': ["sort"]
})
.bind('select_node.jstree', function (event, data) { //綁定的點擊事件
var inst = data.instance;
var selectedNode = inst.get_node(data.selected);
if (data.node.text == "左" || data.node.text == "右") {
loadConfigSon(inst, selectedNode, data);  子節點加載JS方法
}
});url

//子節點加載地址事件

function loadConfigSon(inst, selectedNode, data) {
var js = {
parent: data.node.id.split('_')[0],  //父節點ID
txt: data.node.text
};
$.ajax({
url: "子節點的查詢方法地址",
dataType: "json",
type: "get",
data: js,
success: function (data) {
if (data.length>0) {
selectedNode.children = [];//狀況自節點的數據
$.each(data, function (i, item) {//循環返回數據
inst.create_node(selectedNode, item, "last");//加載子節點數據
});
inst.open_node(selectedNode);//打開父節點
} else {
bootbox.alert("暫無數據!");
}
}
});
}get

相關文章
相關標籤/搜索