actionscript-3 - 柔性 4 : XML Literals with conditions

标签 actionscript-3 apache-flex air e4x

有没有办法在 Flex 中做类似下面的事情(伪代码):

var x:XML = <xml>
  if(condition){
    <tag>hello</tag>
  }
</xml>;

这将返回 <xml><tag>hello</tag></xml>如果条件为真且<xml></xml> (或 <xml/> )如果条件为假?

附加说明:我知道如何附加子项等。我正在寻找一种在文字表达式中执行此操作的方法。

最佳答案

我对它的简单性以及 AS3 的强大性感到非常惊讶。以下实际有效:

var x:XML = <xml>{condition ? <tag>hello</tag> : ""}</xml>;

关于actionscript-3 - 柔性 4 : XML Literals with conditions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13860722/

相关文章:

actionscript-3 - 使用curveTo绘制完美圆的一部分

linux - 在 Linux 中为 Adob​​e Air 应用程序设置自定义菜单文件夹

java - Intellij IDEA |打包AIR应用程序ios失败

java - Flex 文件下载

flash - 使用 Flexbuilder 维护以 Flash 设计的 Web 应用程序是否可行

apache-flex - Flex : Remove OK Button from Alert. 显示?

ios - Flash builder - 可以使用免费的 Apple 帐户直接编译到设备吗?

ios - AS3 异步位图创建 iOS

actionscript-3 - 向 Flex 移动应用程序添加自动更新功能

actionscript-3 - AS3 Flash 从影片剪辑内的影片剪辑中调用主时间线