【问题标题】:How I can use EX4 with an attribute containing dash character?如何将 EX4 与包含破折号的属性一起使用?
【发布时间】:2012-10-26 16:54:17
【问题描述】:

有这个代码

var images:XML = 
    <elements>
        <el data-custom="abc"/>
        <el data-custom="def"/>
        <el data-custom="ghi"/>
    </elements>

如何使用 e4x 表达式获取属性值?请注意属性名称中的破折号“-”字符。我在 Flex 中使用它,但它可能是 E4X 标准的一般问题。

你显然不能使用:

 trace(elements.el.@data-custom)

【问题讨论】:

    标签: javascript xml apache-flex actionscript e4x


    【解决方案1】:

    在许多情况下,我更喜欢使用 XML/XMLList 的 attribute() 方法而不是 (@) 标识符。它也适用于属性名称,这些属性名称也是保留的 Actionscript 单词,如“class”、“package”、“return”等......

    【讨论】:

      【解决方案2】:

      经过一些不那么简单的搜索后,我为后代找到了答案

      elements.el.@['data-custom'];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-09-15
        • 1970-01-01
        • 1970-01-01
        • 2012-08-31
        • 1970-01-01
        • 2021-04-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多