如何动态更新dojo树数据 [英] How to update dojo tree data dynamically
本文介绍了如何动态更新dojo树数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何动态更新dojo.dijit.tree组件的数据。目前我正在使用dojo.data.ItemFileReadStore和dijit.tree.ForestStoreModel创建树。一旦我创建树,我想定期重新加载新的JSON数据。
I would like to know how ot update the data of the dojo.dijit.tree component dynamically. At the moment I'm creating the tree using dojo.data.ItemFileReadStore and dijit.tree.ForestStoreModel. Once I create the tree, I would like to reload it periodically with new JSON data.
这是我现在创建树的方式:
This is how I create the tree at the moment:
<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" />
提前感谢
推荐答案
明确地说,你不能,但这并不意味着你不能把事情劈成碎片,而是死亡。
Explicitly you "can't", but that doesn't mean you can't hack things to pieces and die trying.
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();
},
这篇关于如何动态更新dojo树数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文