How I can use EX4 with an attribute containing dash character?
-
14-07-2021 - |
Pregunta
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)
Solución 2
After some not so easy search I found an answer for the posterity
elements.el.@['data-custom'];
Otros consejos
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...
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow