如何将新节点添加到dijit.Tree

时间:2010-05-03 15:36:33

标签: dojo tree insertion

我想将新节点添加到dijit.ree作为当前所选节点的兄弟节点。我找到了示例代码(我是dojo的新手),它使用ItemFileWriteStore的newItem方法向树添加一个新项,但新项总是出现在树的底部。如何在指定位置添加到商店,特别是与当前选择对应的位置?欢迎使用示例代码示例:)

谢谢, 拉里

3 个答案:

答案 0 :(得分:2)

您需要找到当前所选节点的父项,并将该项用作新创建项的父项。

store.newItem(itemObj, {parent : parentItem, attribute : children});

通常,商店中的商品没有指向其父级的后退指针。所以你可能需要自己维护。例如,您可以将父项的id存储在子项中,并使用fetchItemByIdentity来获取父项。

答案 1 :(得分:2)

我明白了;这是未来搜索者的答案。使用newItem作为Alex建议。然后使用model.pasteItem重新定位新项。 pasteItem接受父(selectedNode.item.parent [0])和位置(selectedNode.getIndexInParent()+ 1)

拉​​里

答案 2 :(得分:2)

store.newItem发出错误(未捕获错误:dojo.data.ItemFileReadStore:无效的属性参数。)。到目前为止无法真正找到解决方法,我的商店没有重复的ID。

因此我尝试使用 model.newItem(newItem,parentItem)。 这非常正常。

谢谢, Srilatha。

相关问题