Zounadire
Zounadire

Reputation: 1564

Adding a new item to the store of a dojo tree does not trigger an update

I'am trying to add a new node to a dijit.tree by adding the node to its store. The node is added to the store but the treeModel is not updated.

Here the setup of my store, model and tree

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

Here the function which adds the item

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

What am I doing wrong?

EDIT The above code woks it was just an update problem

Upvotes: 3

Views: 3359

Answers (1)

Yichz
Yichz

Reputation: 9681

try

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

Upvotes: 1

Related Questions