Login Register

Adding items to programatically created tree

Hi all,

I have an xml dom from which i create an ItemFileWriteStore datastore, which I use as the Store for my Tree, which i also programatically create like so

var tree = new dijit.Tree({
                                        persist:false,
                                        store: store,
                                        id: "myTree"
                                }, this.dojo.byId("myDivInsideMyContentPane");

inside a ContentPane. So far so good, the Tree displays all the Items as Nodes correctly.

Now I add an Item to the root of my Store like so

store.newItem({id:"newID", className:"schemas.Folder", seeValue:"New Folder"}, null);

(I also add this item as an xml node to my xml dom) So far so good again, the tree shows the new node. But now when I clear the ContentPane by calling

myContentPane.destroyDescendants(); (which works fine)

and then try to recreate my Store from my xml dom, the Tree only gets drawn with displaying the node that i just added. It does not display the original nodes.

I have checked the json object that I create for my store and it DOES contain ALL the Items, but the Tree only displays the newly added one.

I have tried everything possible but am not able to figure out why this happens.

The json object I create looks like this

var jsonDom = {
        label: "seeValue",
        items:[
                {
                        id: "8",
                        className: "schemas.Folder",
                        seeValue: "[Folder] Inventory"
                       
                },{
                        id: "45532",
                        className: "schemas.Folder",
                        seeValue: "[Folder] Authorization"
                       
                }
       
        ]
};

PLEASE PLEASE let me know if I am doing something wrong. I will be very grateful for ANY help give.

Thanks in advance,
pix.

tree newItem

//

I'm sorry, i didn't quite follow..

I sorry but I didn't get any description or explanation only an email in which was a message "parent object of newItem cannot be null" but then what should it be?

Could you please please tell me what the parent should be?

I have looked at the example (below) provided by dojo itself and they use null when the item is added to the root.

"dojo-release-1.1.0\dojox\data\tests\test_Tree_vs_jsonPathStore.html"

In the example is this function

function addItem(){
                        var store = dijit.byId("myTree").store;
                        var pInfo = selectedItem ? {parent: selectedItem, attribute:"children"} : null;
                        console.debug("pInfo : " + pInfo);
                        store.newItem({id: dojo.byId('newId').value,name:dojo.byId("label").value,someProperty:dojo.byId("someProperty").value},pInfo);
                        resetForms();
                }

and the object pInfo is set to null if theere isnt any item selected which would be in the case of adding an item to the root.

Could you please tell me then in the case where my datastore doesnot have a root, what the parent object should be.

Also I should add that when I do add an item as a child of an already existing item to the tree and store i DO create a parent object like so

tree.store.newItem({id:childNodeDetails.id, className:childNodeDetails.className, seeValue:childNodeDetails.title}, {parent: parentTreeNode.item, attribute:"children"});

Thanks again,
pix.

SOLVED!!!

The mistake was mine. It was just a question of timing. I was trying to select the last node in the tree before the tree had finished getting displayed. As a result of which the entire tree was getting drawn out but only from the last node down (the one i was trying to select). The rest of the tree was getting drawn above it but was hidden because the content pane did not extend that far.
Cheers!
pix.