0

I'd like to know if it's possible to filter using two values or more. In this example:

var destinations:XML = <destinations>
    <destination location="japan">
    <exchangeRate>400</exchangeRate>
    <placesOfInterest>Samurai History</placesOfInterest>
</destination>
<destination location="japan">
        <exchangeRate>60</exchangeRate>
        <placesOfInterest>Samurai History</placesOfInterest>
</destination>
    <destination location="australia">
        <exchangeRate>140</exchangeRate>
        <placesOfInterest>Surf and BBQ</placesOfInterest>
</destination>
<destination location="peru">
        <exchangeRate>300</exchangeRate>
        <placesOfInterest>Food</placesOfInterest>
</destination>
<destination location="france">
        <exchangeRate>300</exchangeRate>
        <placesOfInterest>Food</placesOfInterest>
    </destination>
</destinations>;

//FILTER -------------------
var filtered:XMLList = destinations.destination.(placesOfInterest != "Food", exchangeRate != 300);
trace(filtered);

It doesn't work if there are more nodes with the same values. It shows first all the nodes without "Food" and after that all the nodes without "300". So, it shows some "Food" results.

Is there an easy way for filtering two or 3 values, say Name, Surname? Or name, surname and company.

Thanks in advance

4

1 回答 1

1

这应该有效:

var filtered:XMLList = destinations.destination.(placesOfInterest != "Food" && exchangeRate != "300");
trace(filtered);

理论上,您可以在括号之间放置任何表达式,例如使用if语句时。这是文档

另请注意,在将数据与 XML 进行比较时,您应该使用String.

另一个不太优雅的解决方案可能是使用两步过程。

var filtered:XMLList = destinations.destination.(placesOfInterest != "Food");
filtered = filtered.(exchangeRate != "300");
trace(filtered);
于 2013-08-26T20:00:08.510 回答