我想知道,如何在JsTree上加载一个新的数据,我必须在点击时加载数据,就像这样。
function showTree(group_id){
$("#jstree").jstree({
"core": {
"themes": {
'name': 'proton',
'responsive': true
},
"data": {
type: "POST",
url: "/menu/tree",
dataType: "json",
data: {
group_id: group_id
},
success: function (data) {
data.d;
console.log(data);
$(data).each(function () {
return { "id": this.id };
});
}
},
},
"checkbox" : {
"keep_selected_style" : false
},
"plugins" : [ "checkbox" , "types", "json_data"]
});
}
当我第一次调用函数时,它的工作,但第二次使用不同的数据时,数据没有改变。
注意:不同的数据是来自于检查值
数据示例:new.I改成:新的。
{
id : "1"
text : "Test 1"
state : {
selected : true
},
}
{
id : "2"
text : "Test 2"
state : {
selected : false
},
}
我改成:
{
id : "1"
text : "Test 1"
state : {
selected : false
},
}
{
id : "2"
text : "Test 2"
state : {
selected : false
},
}
我可以只改变从JsTree中选择的数据吗?
jsTree的初始化与 $("#jstree").jstree()
是一次性的东西,不打算重复使用。调用 jstree
函数可能无法重新创建树。如果你使用的是ajax来源的数据,你可以使用jsTree的函数用新数据重新绘制。
刷新函数可以从ajax url加载新数据。
function updateTree(group_id){
$("#jstree").jstree(true).settings.core.data = {
type: "POST",
url: "/menu/tree",
dataType: "json",
data: {
group_id: group_id
},
success: function (data) {
data.d;
console.log(data);
$(data).each(function () {
return { "id": this.id };
});
}
};
$("#jstree").jstree(true).refresh();
}