使用 Dojo 1.3,在将子项(即文件夹或项)添加到树后,有没有办法通过刷新或其他方法立即反映它?
badhorsie
问问题
4540 次
3 回答
0
来自官方Dojo 手册
更新树
人们经常问:
如何更新树(添加或删除项目?)
您不能直接更新树,而是需要更新模型。通常模型连接到数据存储,在这种情况下,您需要更新数据存储。因此,您需要使用允许更新(通过其官方 API)的数据存储,例如 dojo.data.ItemFileWriteStore。
如何从商店刷新树?
这不受支持。商店需要将数据的任何更改通知树。目前,这实际上只有 dojo.data.ItemFileWriteStore 支持(开箱即用),因为设置一个客户端-服务器 dojo.data 源,服务器在数据发生更改时通知客户端非常复杂,超出了dojo,这是一个仅限客户端的解决方案。
于 2009-04-07T12:38:02.827 回答
0
我已经解决了这个问题,不需要刷新。
_refreshNodeMapping: function (newNodeData) {
if(!this._itemNodesMap[newNodeData.identity]) return;
var nodeMapToRefresh = this._itemNodesMap[newNodeData.identity][0].item;
var domNode = this._itemNodesMap[newNodeData.identity][0].domNode;
//For every updated value, reset the old ones
for(var val in newNodeData)
{
nodeMapToRefresh[val] = newNodeData[val];
if(val == 'label')
{
domNode.innerHTML = newNodeData[val];
}
}
}
于 2014-09-08T17:54:17.373 回答
0
比如说,如果您的模型有查询 `{type:'continent'} - 意味着具有此属性的任何项目都是顶级项目,那么以下模型扩展将监视更改并刷新树的视图
var dataStore = new ItemFileWriteStore( { ... });
new Tree({
store: dataStore,
model: new ForestModel({
onNewItem: function(item, parentInfo){
if(this.store.getValue(item, 'type') == 'continent'){
this._requeryTop();
}
this.inherited(arguments);
}
}
});
这应该反过来childrenChanged
在树中调用并在每次添加新项目时更新它。
参见模型参考
另外,如果添加的项目不是顶级项目,则应该可以使用此语句立即更新。parent
是已将项目添加到其children
.
tree._collapseNode(parent);
parent.state = 'UNCHECKED';
tree._expandNode(parent);
可以通过以下方式实现或多或少的“标准”刷新树。它没有被添加到基本实现的原因,我认为是因为它会破坏与树上 DnD 功能的链接
dojo.declare("My.Tree", [dijit.Tree], {
// Close the store? (So that the store will do a new fetch()).
reloadStoreOnRefresh : true,
update: function() {
this.model.store.clearOnClose = this.reloadStoreOnRefresh;
this.model.store.close();
// Completely delete every node from the dijit.Tree
delete this._itemNodesMap;
this._itemNodesMap = {};
this.rootNode.state = "UNCHECKED";
delete this.model.root.children;
this.model.root.children = null;
// Destroy the widget
this.rootNode.destroyRecursive();
// Recreate the model, (with the model again)
this.model.constructor(this.model)
// Rebuild the tree
this.postMixInProperties();
this._load();
}
}
);
于 2012-08-01T07:52:26.360 回答