如何向 dijit.Tree 添加新节点

发布于 2024-08-31 03:40:18 字数 177 浏览 6 评论 0原文

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

谢谢, 拉里

I want to add a new node to a dijit.ree as a sibling of the currently selected node. I've found sample code (I'm new to dojo) that adds a new item to the tree using the newItem method of ItemFileWriteStore, but the new item always appears at the bottom of the tree. How would I add to the store at a specified position, in particular the position corresponding to the current selection? Pointers to sample code would be welcome :)

Thanks,
Larry

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无法言说的痛 2024-09-07 03:40:19

我想通了;这是未来搜索者的答案。按照 Alex 的建议使用 newItem 。然后使用 model.pasteItem 重新定位新项目。 PasteItem 采用父级 (selectedNode.item.parent[0]) 和位置 (selectedNode.getIndexInParent()+1)

Larry

I figured it out; here's the answer for future searchers. Use newItem as Alex suggested. Then use model.pasteItem to reposition the new item. pasteItem takes a parent (selectedNode.item.parent[0]) and a position (selectedNode.getIndexInParent()+1)

Larry

苦行僧 2024-09-07 03:40:19

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

因此我尝试使用model.newItem(newItem,parentItem)
这完全可以正常工作。

谢谢,
斯里拉塔。

store.newItem is giving an error (Uncaught Error: dojo.data.ItemFileReadStore: Invalid attribute argument. ). Could not really find a fix for this so far and my store does not have duplicate id's.

Hence i tried using model.newItem(newItem, parentItem).
This works perfectly alright.

Thanks,
Srilatha.

孤单情人 2024-09-07 03:40:18

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

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

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

You need to find the parent item of current selected node and use that item as the parent of the newly created item.

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

Normally an item in the store doesn't have a back pointer points to its parent. So you may need to maintain that yourself. For example, you can store the parent item's id in the child item and use fetchItemByIdentity to get the parent item.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文