Play 框架无法将 #{set} 标签分配的变量读取到 #i{if} 标签中?



我对Playframework 1.2.5有问题,我的问题是:

我如何使用#set {.../}标记为#{if .../}标签的变量?

这是我的Java代码 - (它可以使用):

...
renderArgs.put("blockInsert", true);
...

这是我的HTM代码 - (它可以使用):

...
#{set allowInsert:"${!blockInsert}" /}
...

使用$ {}和#{get/} - (它起作用)读取变量:

blockInsert == ${blockInsert}<br/>
allowInsert == #{get 'allowInsert' /}<br/>

使用#{if/}标签上的变量 - (效果不佳):

using variable from renderArgs - (it works) 
#{if blockInsert}
    cant't insert
#{/if}
#{else}
    can insert
#{/else} 
<br/>
using variable from #{set} tag - (it not works) 
#{if allowInsert}
    can insert
#{/if}
#{else}
    cant't insert
#{/else}
...

当我运行此页面时,输出为:

blockInsert == true
allowInsert == false 
using variable from renderArgs - (it works) cant't insert 
using variable from #set} tag - (it not works) can insert 

使用

%{allowInsert=!blockInsert}%

而不是设置。设定标签的结果是字符串。或者您调整if语句:

#{if allowInsert == "true"}
    can insert
#{/if}
#{else}
    cant't insert
#{/else}

最新更新