2011-08-29 61 views
2

我试图通过将节点添加到其商店来将新节点添加到dijit.tree。 节点已添加到商店,但树模型未更新。将新项目添加到dojo树的商店不会触发更新

这里我的店,模型和树

this.treeStore = new dojox.data.JsonRestStore({ 
    target:"dn/", 
    idAttribute:"serviceId", 
    labelAttribute:"name" 
}); 


this.treeModel = new dijit.tree.ForestStoreModel({ 
    store: this.treeStore, 
    rootLabel:'All Files', 
    deferItemLoadingUntilExpand: true, 
    mayHaveChildren:function(item){ return item.children != undefined && item.children.length>0}, 
    childrenAttrs: ["children"] 
}); 

this.docTree = new dijit.Tree({ 
    id:"myTree", 
    showRoot:false, 
    model: this.treeModel, 
    persist: false, 
},this.dijitTree); 

这里它增加了项目

function addNewNode(item){ 
    var self=this; 
    console.log(item); 

    this.treeModel.getRoot(function(root){ 
     var tmp=self.treeStore.newItem(item,{parent:root, attribute:[]}); 
     self.treeStore.save(); 
    }); 
} 

我在做什么错功能的设置?

编辑 上面的代码炒菜那只是一个更新的问题

+0

只是为了健全检查,你能尝试森林模型做的getChildren,看看是否变化传递到商店? – hugomg

+0

嗨丢失。转出我只有一个更新的问题......服务器上的最新XP的脚本。无论如何,上面的代码有效,我认为我们中的一些人可以用它作为他们开发的基础。我应该将问题更改为“如何将新项目添加到dijit树”? – Zounadire

+0

随你做。我只是注意到,如果你使用新的dojo.store API,它会有点不同:http://dojotoolkit.org/documentation/tutorials/1.6/store_driven_tree/ – hugomg

回答

1

尝试

store.newItem(item); 
store.save(); 
theGrid.setStore(store); 
theGrid.update(); 
theGrid._refresh(); 
+0

store.save()在调用newItem()后是必需的。感谢+1 –

相关问题