[英]Dynamic E4X expressions
My last Q: E4X select Nodes where descendants can be either A OR B or A && B was concerning how to query for multiple attribute values in E4X expressions, which @Patrick answered with this: 我的最后一个问题: E4X选择后代可以是A OR B或A && B的节点,涉及到如何查询E4X表达式中的多个属性值,@ Patrick对此回答:
xml.Item.(descendants('ProductRange').(@id=="1" || @id=="2").length()>0);
Now the question is, how do we make the values dynamic using an array or string? 现在的问题是,如何使用数组或字符串使值动态化?
A bit like this, but this DOES NOT work: 有点像这样,但这不起作用:
var attributeValues:String = "@id==\"1\" || @id==\"2\" || @id==\"3\" || @id==\"4\"";
xml.Item.(descendants('ProductRange').(attributeValues).length()>0);
Many Thanks 非常感谢
An array holding your values can be made for example and then using an indexOf search to find the id in it : 例如,可以创建一个保存您的值的数组,然后使用indexOf搜索在其中找到ID:
var xml:XML=<Items>
<Item name="aaa">
<ProductRanges>
<ProductRange id="1" />
</ProductRanges>
</Item>
<Item name="bbb">
<ProductRanges>
<ProductRange id="2" />
</ProductRanges>
</Item>
<Item name="ccc">
<ProductRanges>
<ProductRange id="1" />
<ProductRange id="3" />
<ProductRange id="2" />
</ProductRanges>
</Item>
</Items>;
// you values filled from whatever source
var valuesToFind:Array=["1","2", "3"];
// search if @id exist into your values
// and unsure that there is any node returned
var res:XMLList=xml.Item.(descendants('ProductRange').(valuesToFind.indexOf(@id.toString())>=0).length()>0);
trace(res);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.