[英]Dynamic E4X expressions
我的最后一個問題: E4X選擇后代可以是A OR B或A && B的節點,涉及到如何查詢E4X表達式中的多個屬性值,@ Patrick對此回答:
xml.Item.(descendants('ProductRange').(@id=="1" || @id=="2").length()>0);
現在的問題是,如何使用數組或字符串使值動態化?
有點像這樣,但這不起作用:
var attributeValues:String = "@id==\"1\" || @id==\"2\" || @id==\"3\" || @id==\"4\"";
xml.Item.(descendants('ProductRange').(attributeValues).length()>0);
非常感謝
例如,可以創建一個保存您的值的數組,然后使用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.