E4X 获取元素的下一个兄弟元素

发布于 2024-08-18 13:05:17 字数 363 浏览 4 评论 0原文

我有一个对 XML 节点的引用,它是更大的 XML 树的一部分。有没有办法在不访问父级并查找它的情况下获取下一个/上一个同级元素?我正在寻找像 DOM 的 nextSibling 这样的东西。

编辑:鉴于 E4X 没有自然的方法来执行此操作,我将坚持以下内容(除了在我的情况下,我会将实际索引存储在某处):

// next sibling:
node.parent().children()[ node.childIndex() + 1 ]
// previous sibling:
node.parent().children()[ node.childIndex() - 1 ]

I have a reference to a XML node which is part of a bigger XML tree. Is there a way to get that elements next/previous sibling without accessing the parent and looking for it? Something like DOM's nextSibling would be what I look for.

edit: Given that there is no natural way to do this with E4X, I'll just stick to the following (except that in my case, I'll store the actual index somewhere instead):

// next sibling:
node.parent().children()[ node.childIndex() + 1 ]
// previous sibling:
node.parent().children()[ node.childIndex() - 1 ]

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

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

发布评论

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

评论(2

爱你不解释 2024-08-25 13:05:17

我在 ECMA-357 第二版中没有看到任何此类方法。此外,“兄弟姐妹”似乎没有出现在我的标准副本中的任何地方。如果存在任何此类方法,那么它们之所以存在,是因为 Adob​​e 将它们添加为规范的扩展。

I don't see any such methods in ECMA-357, 2nd edition. Moreover, "sibling" doesn't seem to appear anywhere in my copy of the standard. If any such methods exist, they exist because Adobe added them as extensions to the spec.

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