问题
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