Xml 动态E4X表达式
我最后一个问题是: 关于如何查询E4X表达式中的多个属性值,@Patrick回答如下:Xml 动态E4X表达式,xml,actionscript-3,dynamic,e4x,Xml,Actionscript 3,Dynamic,E4x,我最后一个问题是: 关于如何查询E4X表达式中的多个属性值,@Patrick回答如下: xml.Item.(descendants('ProductRange').(@id=="1" || @id=="2").length()>0); 现在的问题是,我们如何使用数组或字符串使值成为动态的 有点像这样,但这不起作用: var attributeValues:String = "@id==\"1\" || @id==\"2\" || @id==\"3\" || @id==\"4\""; xm
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);
非常感谢例如,可以创建一个包含您的值的数组,然后使用搜索在其中查找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);
var-xml:xml=
;
//您可以从任何来源填充值
var valuesToFind:Array=[“1”、“2”、“3”];
//搜索您的值中是否存在@id
//并且不确定是否返回了任何节点
var res:XMLList=xml.Item.(后代('ProductRange')(valuesToFind.indexOf(@id.toString())>=0.length()>0);
微量元素(res);
要确认的是,这种索引技术不会在值“14”中错误地找到id值“1”???indexOf将在数组中搜索您想要的值,因为在您的值中没有“14”以查找没有pb。我们只是反复检查,如果您有一个节点,搜索“1”不会错误地找到它(因为“1”在“14”中)。。。然而,它看起来确实很好,这是伟大的!id=“14”,但数组值仅为“1”、“2”、“3”,因此一切正常。indexOf不会在每个字符串内搜索,而只搜索每个值。