多属性 xml 过滤器 as3 e4x
我正在尝试提出最好的 xml 模式来支持标签过滤。然后是根据任意数量的标签过滤 xml 的方法。所以这里是 xml:
var videoXML:XML=
<?xml version="1.0" encoding="UTF-8"?>
<videos>
<video> <tags label="dogs,brown,lawns" /> </video>
<video> <tags label="dogs,cats" /> </video>
<video> <tags label="cats,lawns" /> </video>
</videos>
我现在过滤的方式是:
var filteredList:XMLList = videoXML..video.tags.(@label.indexOf("lawns") != -1 && @label.indexOf("dogs") != -1);
它只会返回带有“草坪”和“狗”标签的视频,这一切都很好。
但我想要一种方法,可以传入任意数量的标签并获取该过滤器的结果。
类似于:
function getFilteredByTags(...tags):XMLList{
}
关于如何实现这一点有什么想法吗?
谢谢!
I am trying to come up with the best xml schema to support tag filtering. And then a method to filter the xml on an arbritary amount of tags. So here is the xml:
var videoXML:XML=
<?xml version="1.0" encoding="UTF-8"?>
<videos>
<video> <tags label="dogs,brown,lawns" /> </video>
<video> <tags label="dogs,cats" /> </video>
<video> <tags label="cats,lawns" /> </video>
</videos>
And the way I am filtering now is:
var filteredList:XMLList = videoXML..video.tags.(@label.indexOf("lawns") != -1 && @label.indexOf("dogs") != -1);
which would return only videos that had the tag "lawns" and "dogs", which is all good and fine.
But I want a method that I can pass in as many tags as I want and get the results of that filter.
Something like:
function getFilteredByTags(...tags):XMLList{
}
Any ideas on how to accomplish this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想不出更好的方法,但您的函数可以计算有多少个标签,然后对该计数运行 switch 语句并对标签数量执行正确的 e4x。
I can't come up with a better way but your function could count how many tags there are then run a switch statement on that count and do the right e4x for the number of tags.
未经测试,但应该可以工作。™
将您的 XML 更改为:
返回具有多个标签的视频的函数:
Untested, but Should Work.™
Change your XML to:
Function to return videos with multiple tags: