1

我想创建一个 e4x 对象。我想动态地继续为其添加属性并在以后添加值。例如 var node = <node />; //一些代码 1) 将属性添加到“节点” 2) 将值添加到“节点”

我还找到了 Flex3 的此类示例,但没有找到 Javascript 的示例。任何进一步的文件也将不胜感激

4

1 回答 1

0

如果要添加属性或值

var node = <node/>
node.@id = 123
node.toXMLString()
//returns
//<node id="123"/>

如果您想添加动态命名的属性,请使用方括号

node.@["prioritory"] = "high"
//returns
//<node id="123" prioritory="high"/>

添加子元素也是一样的

node.description = "Warning"
node.toXMLString()
//<node id="123" prioritory="high">
//  <description>Warning</description>
//</node>

node["location"] = "R23"
node.toXMLString()
//<node id="123" prioritory="high">
//  <description>Warning</description>
//  <location>R23</location>
//</node>

我发现此链接在尝试刷新我的 e4x http://wso2.org/project/mashup/0.2/docs/e4xquickstart.html时很有帮助

于 2013-05-04T22:21:55.320 回答