我想知道如何动态更新 dojo.dijit.tree 组件的数据。目前我正在使用 dojo.data.ItemFileReadStore 和 dijit.tree.ForestStoreModel 创建树。创建树后,我想使用新的 JSON 数据定期重新加载它。
这就是我现在创建树的方式:
<div dojoType="dojo.data.ItemFileReadStore" jsId="myStore" url=getJSONResult></div>
<div dojoType="dijit.tree.ForestStoreModel" jsId="myModel" store="myStore" query="{type:'cat'}" rootId="myRoot" rootLabel="Data" childrenAttrs="children"></div>
<div dojoType="dijit.Tree" model="myModel" labelAttr="sname" label="Data" />
提前致谢。
最佳答案
明确地说你“不能”,但这并不意味着你不能把事情搞砸然后死于尝试。
refreshTree : function(){
dijit.byId("myTree").dndController.selectNone(); // As per the answer below
// Credit to this discussion: http://mail.dojotoolkit.org/pipermail/dojo-interest/2010-April/045180.html
// Close the store (So that the store will do a new fetch()).
dijit.byId("myTree").model.store.clearOnClose = true;
dijit.byId("myTree").model.store.close();
// Completely delete every node from the dijit.Tree
dijit.byId("myTree")._itemNodesMap = {};
dijit.byId("myTree").rootNode.state = "UNCHECKED";
dijit.byId("myTree").model.root.children = null;
// Destroy the widget
dijit.byId("myTree").rootNode.destroyRecursive();
// Recreate the model, (with the model again)
dijit.byId("myTree").model.constructor(dijit.byId("myTree").model)
// Rebuild the tree
dijit.byId("myTree").postMixInProperties();
dijit.byId("myTree")._load();
},
这将刷新您的树。
关于javascript - 如何动态更新道场树数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5409097/