javascript - 如何动态更新道场树数据

标签 javascript dojo tree

我想知道如何动态更新 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/

相关文章:

javascript - jQuery - mouseenter 上的 SlideDown > 延迟 > mouseleave 上的 SlideUp

java - 使用列表/表中的 json 创建树

ruby-on-rails - Ruby 创建递归目录树

javascript - 删除/重置 DOM 节点

javascript - dojo 1.9 自定义小部件扩展 dijit/form/DateTextBox 时出错

python - 如何将 JSON 数据转换为树形图像?

javascript - 最佳实践工厂 angular.js 1.2

javascript - 我的辅助函数应该放在哪里?

javascript - 在 v5 中扩展 d3.selection——这是正确的做法吗?

Dojo 1.7 自定义构建 - 如何从发布文件夹中删除未使用的文件