问题描述
正常的html代码:
<select id = "game_duration">
<option>01 hour</option>
<option>02 hour</option>
<option>03 hour</option>
<option>04 hour</option>
<option>05 hour</option>
<option>Never end</option>
</select>
要@select Play框架...
我尝试按照教程进行操作,但它只打印了@的纯HTML格式.选择标签
我是新手,所以有人可以帮我吗?
非常感谢.
To @select of Play framework...
I tried following Tutorial but it only printed plain html of the @select tag..
I'm new to play thus can anyone please help me?
Thank you very much.
推荐答案
首先在视图的开头导入helper
包:
First import helper
package(s) at the beginning of your view:
@import helper._
因此您可以使用该示例:
So you can use that sample:
@select(
gameForm("game_duration"),
options(Seq("01 hour","02 hour","03 hour","Never end")),
'_label -> "Game duration", '_default -> "-- Select duration --"
)
或者,您也可以使用该代码而无需事先导入helper
软件包
Alternatively you can also use that code without previous importing helper
package(s)
@helper.select(
gameForm("game_duration"),
helper.options(Seq("01 hour","02 hour","03 hour","Never end")),
'_label -> "Game duration", '_default -> "-- Select duration --"
)
重要:如果Seq(...)
版本在编译时失败,请尝试使用options(List("01 hour","02 hour","03 hour","Never end"))
.
important: Try to use options(List("01 hour","02 hour","03 hour","Never end"))
if Seq(...)
version will fail while compiling.
顺便说一句,使用数字值(即int
-更易于在数据库中存储和搜索)可能会更好:
btw, most probably it would be better using numeric values (ie int
- easier to store and search in DB):
...
helper.options("60" -> "01 hour","120" -> "02 hour","180" -> "03 hour", "9999" -> "Never end"),
...
还请检查此答案以获取更多示例
Also check this answer for more samples
这篇关于在播放框架中填充HTML下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!