这是Layke的解决方案(否则工作正常)通过商业网站的预生产测试发现的问题。
案例1:
- 创建&填充树。
- 单击要选择的节点。
- 在Layke的解决方案中执行refreshTree。
- 点击一个节点,出现错误“this.labelNode is undefined”。
现在重新开始,情况2:
- 创建&填充树。
- 单击要选择的节点。
- 按住Ctrl键点击之前选择的节点。
- 在Layke的解决方案中执行refreshTree。
- 点击一个节点,没有错误。
存储的对第一个选择的选择引用正在用于在进行第二个选择时撤消选择属性(背景颜色等)。 不幸的是,被引用的对象现在处于比特桶中。修改后的代码 似乎是生产就绪的,即没有任何预生产测试失败。
解决的办法是把:
之前上述Layke的refreshTree溶液的第一线
Tree.dndController.selectNone();
。
针对元的建议,那就是:
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();
}
感谢您的回答Laykes。你的脚本确实刷新了树渲染。但是,在这个例子中,我无法在其上加载新数据。我已经实现了定期刷新,调用你创建的函数。我的商店将url属性设置为包含JSON数据的文件名。我正在更改文件上的数据,但树总是呈现初始数据。你知道如何在其上加载新数据吗? – Zion 2011-03-25 13:10:33
对不起TheLostGuy,我认为你的商店设置为关闭时刷新。添加:dijit.byId(“myTree”)。model.store.clearOnClose = true; – Layke 2011-03-25 15:53:42
非常感谢Laykes。现在这确实对我有用。 干杯! – Zion 2011-04-01 12:38:46