如果我将布尔值传递给视图,例如"checked",如何根据选中的值(即 true或false)显示不同的 html 元素?
#{if ${checked}}
<p>aaa</p>
#{/if}
#{else}
<p>bbb</p>
#{/else}
我尝试了上面的代码,但失败了...
#{if checked}
<p>aaa</p>
#{/if}
#{else}
<p>bbb</p>
#{/else}
${} 语法仅用于将值打印到模板中。在 #{if } 标签中,playframework 需要时髦的语法。
另外,请查看 #{if} 标记的文档。
除了@aaberg内联响应之外,如果:
<input type="checkbox" ${checked ? 'checked="checked"' : ''} />
<span>The previous checkbox is ${checked ? "checked" : "not checked"} !</span>