【问题标题】:E4X conditional call is not returning anything with only 1 match?E4X 条件调用仅返回 1 个匹配项不返回任何内容?
【发布时间】:2009-02-26 16:02:42
【问题描述】:

好的,这是我的代码:

var xml:XML = 
<xml>
    <typeA amount1="500" amount2="300" amount3="250" date="2008-02-17"/>
    <typeA amount1="500" amount2="300" amount3="250" date="2008-02-16"/>
    <typeA amount1="500" amount2="300" amount3="250" date="2008-02-17"/>
    <typeB amount1="500" amount2="300" amount3="250" date="2008-02-18"/>
    <typeB amount1="500" amount2="300" amount3="250" date="2008-02-19"/>
    <typeC amount1="500" amount2="300" amount3="250" date="2008-02-20"/>
    <typeC amount1="500" amount2="300" amount3="250" date="2008-02-21"/>
    <typeC amount1="500" amount2="300" amount3="250" date="2008-02-20"/>
</xml>;


trace(xml.typeA.(@date == "2008-02-16")); // no results
trace(xml.typeA.(@date == "2008-02-17")); // finds both
trace(xml.typeC.(@date == "2008-02-20")); // finds both
trace(xml.typeC.(@date == "2008-02-21")); // no results

似乎只有在出现超过 1 次时才会找到它。

我做错了吗?

【问题讨论】:

    标签: xml actionscript-3 e4x


    【解决方案1】:

    实际上它找到了它,但因为它只是一个项目,所以它作为一个 XML(而不是 XMList)跟踪它。 为空的节点只会跟踪一个空字符串。

    试试这个:

    <typeA amount1="500" amount2="300" amount3="250" date="2008-02-16">Hello</typeA>
    

    在调试 XML 时,最好使用toXMLString 方法。

    trace(xml.*.(@date="1980-04-29").toXMLString());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-18
      相关资源
      最近更新 更多