在树中的特定位置向Dijit.Tree添加新节点 [英] Adding new node to Dijit.Tree at a particular place in the tree

查看:67
本文介绍了在树中的特定位置向Dijit.Tree添加新节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在向dijit.Tree添加新的Tree节点时遇到了一个奇怪的错误。

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

但是,这似乎只在我第一次向树中添加项目时有效。尝试添加第二个项目时,出现错误:ItemFileWriteStore中的断言失败?

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 ?

此外,当前在树的第一层添加了该节点。我怎么能在一个子树中添加它,比如说第二个树,id:2?

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 ?

谢谢!

推荐答案

断言错误可能是由于id值冲突所致。第二个项目添加的ID是否与第一个不同?
如果将项目添加到商店,它将被添加到顶层,除非您将该项目添加到子数组之一-如果将项目添加到商店,树必须知道将项目放置在哪里它(正确地)假设它是顶级商品。如果您将新项目添加为现有项目的子项目,那么树再次知道它应该去哪里。

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.

这篇关于在树中的特定位置向Dijit.Tree添加新节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆