javascript – 如何动态更新dojo树数据

前端之家收集整理的这篇文章主要介绍了javascript – 如何动态更新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" />

提前致谢.

解决方法@H_301_10@
显然你“不能”,但这并不意味着你不能把事情劈成碎片,而是去尝试.
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();

},

这将刷新你的树.

原文链接:https://www.f2er.com/js/151419.html

猜你在找的JavaScript相关文章