【问题标题】:E4X: Expression not returning what I expectedE4X:表达式没有返回我所期望的
【发布时间】:2009-04-29 18:15:21
【问题描述】:

我有一个 XMLList,我试图从列表中抓取一个带有石头属性 == Opal 但它不起作用,我不明白为什么?

代码如下:

var xml:XML = <bs><variation price="999999999.99" month="OCT" stone="Magic Pet Rock" image="https://www.sussexjewelers.com/birthstone_images/20_PE105-BT.png" style="PE105" gold_color="White" gold_carat="14"/>
<variation price="999999999.99" month="OCT" stone="Opal" image="https://www.sussexjewelers.com/birthstone_images/17_PE105-OP.png" style="PE105-OP" gold_color="Yellow" gold_carat="14"/>
<variation price="33212221.00" month="OCT" stone="Pink Tourmaline" image="https://www.sussexjewelers.com/birthstone_images/16_PE105-PT.png" style="PE105-PT" gold_color="Yellow" gold_carat="14"/></bs>;


var list:XMLList = xml.children();

trace(list) // returns all three variations

list = list.(@stone == 'Opal');

trace(list); // expecting to return the 2nd variation but actually returns nothing.

谁能明白为什么这没有按预期工作?

谢谢。

【问题讨论】:

    标签: actionscript-3 e4x


    【解决方案1】:

    我在弄清楚这个问题之前就发布了这个问题......我需要在跟踪它时添加 toXMLString()。

    trace(list.toXMLString());
    

    【讨论】:

    • 是的,这是一个奇怪的 Flex 调试器问题。如果一个 e4x 表达式只返回一个节点,它就在那里,但跟踪总是空的。
    • 我发现如果xml只有标签和一些属性没有“内容”,那么它不会追踪我们所期望的。当我和你一样期待看到 xml 但得到空白但列表时,我发现了这一点。(@stone == 'Opal').length() 仍然返回正确的数量。
    猜你喜欢
    • 2021-05-30
    • 1970-01-01
    • 2021-12-11
    • 2018-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    相关资源
    最近更新 更多