在播放框架中填充 html 下拉列表 [英] Populate a html drop down list in play framework
问题描述
可能的重复:
在 Play Framework 2.0 模板中使用选项助手
普通的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.
推荐答案
First import helper
package(s) at the start of your view:
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 --"
)
重要: 尝试使用 options(List("01 hours","02 hours","03 hours","Never end"))
如果 Seq(...)
版本在编译时会失败.
important: Try to use options(List("01 hour","02 hour","03 hour","Never end"))
if Seq(...)
version will fail while compiling.
顺便说一句,很可能使用数值会更好(即 int
- 更容易在 DB 中存储和搜索):
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 下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!