E4X 获取元素的下一个兄弟元素
我有一个对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 ECMA-357 第二版中没有看到任何此类方法。此外,“兄弟姐妹”似乎没有出现在我的标准副本中的任何地方。如果存在任何此类方法,那么它们之所以存在,是因为 Adobe 将它们添加为规范的扩展。
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.
这是您要找的吗?
http://livedocs.adobe.com/flex/ 3/langref/flash/xml/XMLNode.html#nextSibling
Is this what you are looking for?
http://livedocs.adobe.com/flex/3/langref/flash/xml/XMLNode.html#nextSibling