我创建了一个基于 TreeStoreModel 的简单树,该树由 ItemFileWriteStore 支持。 我尝试通过删除项目并将其添加到商店来更新我的树,如下所示,但失败了。
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dijit.Tree");
dojo.addOnLoad(function () {
var tmpData = [{
"name" : "Dell",
"type" : "business",
"businessid" : "1",
"projectid" : "1",
"submenu" : [{
"name" : "OTP",
"type" : "product",
"productid" : "100"
}
]
}
];
var tmpData1 = [{
"name" : "Lenovo",
"type" : "business",
"businessid" : "1",
"projectid" : "1",
"submenu" : [{
"name" : "OTP",
"type" : "product",
"productid" : "100"
}
]
}
];
var store = new dojo.data.ItemFileWriteStore({
data : {
label : 'name',
items : tmpData
}
});
var treeModel = new dijit.tree.TreeStoreModel({
store : store,
query : {
type : 'business'
},
childrenAttrs : ["submenu"]
});
var divTestTree = dojo.create("div", null, dojo.body(), "first");
var mytree = new dijit.Tree({
model : treeModel
},
divTestTree);
/* Tree is created at this point */
/* Delete the item from the store, for some reason tempData is being reset*/
store.deleteItem(tmpData[0]);
/* save */
store.save();
/* Tree shows up no more at this point */
/* Try adding new item to the store */
store.newItem(tmpData1[0]);
/* save */
store.save();
/*nothing happens! */
});
我跟随 here 的引导,我一定在这里遗漏了一些非常微不足道的东西。请帮忙。
最佳答案
取自该页面
如何从商店刷新树?
不支持此功能。存储需要将数据的任何更改通知树。目前,这实际上仅由 dojo.data.ItemFileWriteStore 支持(开箱即用),因为设置客户端-服务器 dojo.data 源(其中服务器在数据发生更改时通知客户端)非常复杂,并且超出了范围dojo,这是一个仅限客户端的解决方案。
更新树的唯一方法是重新绘制它:(
关于javascript - Dojo - Dijit.Tree - 更新树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9081692/