如何使用Scala模板和Play框架预填充下拉菜单 [英] How to prefill a dropdown using scala template and play framework

查看:101
本文介绍了如何使用Scala模板和Play框架预填充下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的项目使用scala模板和Play 2.0框架.假设我有一个用户表单,其中包含诸如名称(文本字段),年龄(下拉列表)之类的字段.创建用户时,我将姓名填写为dave,并将年龄选择为25.

I am using scala template and Play 2.0 framework for my project. Let's say I have a user form with fields like name (textfield), age (dropdown). While creating the user I filled name as dave and selected age as 25.

现在在我的编辑屏幕上,我希望我的值被预填充,我知道如何使用文本字段(即,将值设置为userForm('name')),但是下拉菜单呢?怎么做.

Now on my edit screen, I want my values to be prefilled, i know how to do it with textfield (i.e. set value as userForm('name')) but what about the dropdown? how to do it.

推荐答案

感谢Shawn Downs和biesior.

Thanks Shawn Downs and biesior.

好吧,我们可以使用@select scala帮助器类来显示预填充的结果. 喜欢.

Well, we can use @select scala helper class to show the pre-filled result. like.

 @select(userForm("age"),models.Age.values().toList.map(v => (v.getDisplayName(), v.getDisplayName())),'id->"age")

为显示其他选项,我使用了可能的age枚举.

To show other options I have used an enum of possible values of age.

这篇关于如何使用Scala模板和Play框架预填充下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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