Zio*_*ion 9 javascript tree dojo
我想知道如何动态更新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" />
Run Code Online (Sandbox Code Playgroud)
提前致谢.
Lay*_*yke 20
明确地说你"不能",但这并不意味着你不能将事情分解成碎片并且死于尝试.
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();
},
Run Code Online (Sandbox Code Playgroud)
这是一个问题,Layke的解决方案(否则确实有效)可以通过商业网站的预生产测试找到.
情况1:
现在重新开始,案例2:
存储的对第一选择的选择参考用于在进行第二次选择时撤消选择属性(背景颜色等).不幸的是,引用的对象现在位于比特桶中.修改后的代码似乎是生产就绪的,即没有任何预生产测试失败.
解决方案是:
Tree.dndController.selectNone();
Run Code Online (Sandbox Code Playgroud)
在上面的Layke的refreshTree解决方案的第一行之前.
回应元建议,这里是:
refreshTree : function() {
// Destruct the references to any selected nodes so that
// the refreshed tree will not attempt to unselect destructed nodes
// when a new selection is made.
// These references are contained in Tree.selectedItem,
// Tree.selectedItems, Tree.selectedNode, and Tree.selectedNodes.
Tree.dndController.selectNone();
Tree.model.store.clearOnClose = true;
Tree.model.store.close();
// Completely delete every node from the dijit.Tree
Tree._itemNodesMap = {};
Tree.rootNode.state = "UNCHECKED";
Tree.model.root.children = null;
// Destroy the widget
Tree.rootNode.destroyRecursive();
// Recreate the model, (with the model again)
Tree.model.constructor(dijit.byId("myTree").model)
// Rebuild the tree
Tree.postMixInProperties();
Tree._load();
}
Run Code Online (Sandbox Code Playgroud)