tags:

views:

35

answers:

1

Hi,

I am running into a strange error while adding a new Tree node to dijit.Tree.

var rawdata = [{
            label: 'Date',
            id: '1',
            children: [{
                label: 'Life',
                id: '1.1'
            }, {
                label: 'Liberty',
                id: '1.2'
            }]
        }, {
            label: 'Some links (note: the link is <b>not</b> clickable)',
            id: '2',
            children: [{
                id: '2.1',
                label: '<a href="http://dojotoolkit.org"&gt;Dojo Toolkit</a>'
            }, {
                id: '2.2',
                label: '<img src="http://dojofoundation.org/media/img/dojo.logo.png" alt="greatest ever" height="32px" />'
            }, {
                id: '2.3',
                label: '<a href="http://blog.nqzero.com"&gt;my blog</a>'
            }]
        }];

 var store = new dojo.data.ItemFileWriteStore({
                data: {
                    identifier: 'id',
                    label: 'label',
                    items: rawdata
                }
            });

And in order to add item to the tree, I am using the following:

store.newItem({id:'3', label:"New tree node label"});

However, this only seems to work for the first time I add an item to the tree. When trying to add a second item, I get an Error: assertion failed in ItemFileWriteStore ?

Also, currently the node is added at the very first level in the tree. How could I add it in one of the subtree, say the second tree with id:2 ?

Thanks!

+2  A: 

The assertion error may be due to having conflicting id values. Is the second item added with a different id than the first? If you add an item to the store it will be added at top level, unless you add the item to one of the children arrays - the tree has to know where to put the item, if you add it to a store it assumes (correctly) that it is a top level item. If you add the new item as a child of an existing item, then again, the tree knows where it should go.

Andy