多属性 xml 过滤器 as3 e4x

发布于 2024-08-30 02:05:53 字数 786 浏览 9 评论 0原文

我正在尝试提出最好的 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 技术交流群。

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

发布评论

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

评论(2

金橙橙 2024-09-06 02:05:53

我想不出更好的方法,但您的函数可以计算有多少个标签,然后对该计数运行 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.

滿滿的愛 2024-09-06 02:05:53

未经测试,但应该可以工作。™

将您的 XML 更改为:

var videoXML:XML=
<?xml version="1.0" encoding="UTF-8"?>
<videos>
    <video>
        <tag label="dogs" />
        <tag label="brown" />
        <tag label="lawns" />
    </video>
    <video>
        <tag label="dogs" />
        <tag label="cats" />
    </video>
    <video>
        <tag label="cats" />
        <tag label="lawns" />
    </video>
</videos>

返回具有多个标签的视频的函数:

function getFilteredByTags(...tags):XMLList
{
    // Start with a list of all videos
    var foundVideos:XMLList = videoXML.video;

    for each (tag in tags)
    {
        // Filter foundVideos down to those videos that match tag
        foundVideos = foundVideos.(tag.@label == tag);
    }

    return foundVideos;
}

Untested, but Should Work.™

Change your XML to:

var videoXML:XML=
<?xml version="1.0" encoding="UTF-8"?>
<videos>
    <video>
        <tag label="dogs" />
        <tag label="brown" />
        <tag label="lawns" />
    </video>
    <video>
        <tag label="dogs" />
        <tag label="cats" />
    </video>
    <video>
        <tag label="cats" />
        <tag label="lawns" />
    </video>
</videos>

Function to return videos with multiple tags:

function getFilteredByTags(...tags):XMLList
{
    // Start with a list of all videos
    var foundVideos:XMLList = videoXML.video;

    for each (tag in tags)
    {
        // Filter foundVideos down to those videos that match tag
        foundVideos = foundVideos.(tag.@label == tag);
    }

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