سؤال

Having this code

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

How can i get attributes value with an e4x expression? Please note the dash "-" character in the attribute name. I use it in Flex but it could be a general question for the E4X standard.

You can't obviously use:

 trace(elements.el.@data-custom)
هل كانت مفيدة؟

المحلول 2

After some not so easy search I found an answer for the posterity

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

نصائح أخرى

In numerous occasions I prefer using the attribute() method of XML/XMLList instead of the (@) identifier. It also works with the attribute names that are also reserved Actionscript words like "class","package", "return",etc...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top