Adding new node to Dijit.Tree at a particular place in the tree

谁都会走 提交于 2019-12-24 07:51:28

问题


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">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">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!


回答1:


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.



来源:https://stackoverflow.com/questions/3207853/adding-new-node-to-dijit-tree-at-a-particular-place-in-the-tree

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!