gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 07:59:00 25 4
gpt4 key购买 nike

我在使用 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}

关于java - Play 框架无法将 #{set} 标签分配的变量读取到 #i{if} 标签中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13142521/

25 4 0