将新项添加到dojo树的存储中不会触发更新

时间:2011-08-29 13:27:56

标签: dojo tree

我试图通过将节点添加到其商店来向dijit.tree添加新节点。 该节点已添加到商店,但treeModel未更新。

这里是我的商店,模型和树的设置

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();
    });
}

我做错了什么?

修改 上面的代码告诉它只是一个更新问题

1 个答案:

答案 0 :(得分:1)

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