使用 E4X 查找 XML 列表中的不同值
考虑以下 XML 片段:
<book id="5" />
<book id="15" />
<book id="5" />
<book id="25" />
<book id="35" />
<book id="5" />
如何编写 E4X 语句/查询来获取 id
属性中的唯一值列表?我在 JavaScript 非浏览器上下文中使用 E4X。
5
15
25
35
是否有任何类型的 distinct()
或 groupby()
方法有帮助?如果不是的话,这怎么可能实现呢?
Consider this XML snippet:
<book id="5" />
<book id="15" />
<book id="5" />
<book id="25" />
<book id="35" />
<book id="5" />
How can I compose an E4X statement/query to get a list of the unique values in the id
attribute? I'm using E4X in a JavaScript non-browser context.
5
15
25
35
Is there a distinct()
or groupby()
method of any kind that would help? If not, how could this be accomplished?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有 unique 或 groupby 方法。然而,E4X 允许您快速创建非唯一值的 XMLList。
为了使其唯一,您可以获取 XMLList,迭代它,并将每个元素作为键值存储在对象中。
要访问这些值,请使用 for in 循环(而不是 for every in)迭代它们
There is no unique or groupby method. However, E4X allow you to quickly create an XMLList of the values non-unique values.
To make it unique, you can then take the XMLList, iterate through it, and store each element as the key value in an object.
To access these values, iterate through them using a for in loop (not a for each in)
这假定所讨论的属性值不包含竖线“|”字符。如果是这样,则将最底部的管道字符更改为值中不存在的其他字符。这些变量是静态类型的,用于 JIT 执行。希望这能满足您的需要。
This presumes the attribute values in question do not contain a pipe, "|", character. If so then change the pipe character at the very bottom to something else not in the values. The variables are statically typed for JIT execution. Hope this does what you need.