加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

有条件地将属性添加到XML文字中

发布时间:2020-12-16 08:04:44 所属栏目:百科 来源:网络整理
导读:我有以下XML文字: input type='radio' name={funcName} value='true' / 如果cond是true,我想包括checked =’checked’。 我试过这个, input type='radio' name={funcName} value='true' { if (cond) "checked='checked'" else "" } / 但它不工作。 (我真
我有以下XML文字:
<input type='radio'
       name={funcName}
       value='true' />

如果cond是true,我想包括checked =’checked’。

我试过这个,

<input type='radio'
       name={funcName}
       value='true'
       { if (cond) "checked='checked'" else "" } />

但它不工作。

(我真的很想避免重复整个标签。)

选项也有效,这减少了不必要的使用null:
scala> val checked:Option[xml.Text] = None
checked: Option[scala.xml.Text] = None

scala> val xml = <input checked={checked} />
xml: scala.xml.Elem = <input ></input>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读