how to generate option values in Playframework Form helper @select

邮差的信 提交于 2019-12-11 06:57:39

问题



i want to generate a <select> tag in Play Form. but the option values are not fixed. so i coded it as this:

@select(
    myF("server_id"),
    options(
        for(s <- servers){s.getId -> s.getName}
    )
)

however, the compiler tells out that:

Overloaded method value [apply] cannot be applied to (Unit)

cannot i use for sub in option? and how should i code? thx.


回答1:


@select takes a sequence of (String, String) tuples. You already have a sequence (servers), so you just to map them to tuples:

@select(
  myF("server_id"),
  servers.map(s => s.getId -> s.getName)
)


来源:https://stackoverflow.com/questions/20672422/how-to-generate-option-values-in-playframework-form-helper-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!