在播放框架中填充HTML下拉列表 [英] Populate a html drop down list in play framework

查看:80
本文介绍了在播放框架中填充HTML下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
在Play Framework 2.0模板中使用选项帮助程序

Possible Duplicate:
Use of option helper in Play Framework 2.0 templates

正常的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下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆