The right type is: Seq[(String, String)]
. It means a sequence of pairs of String. In Scala there is a way to define pairs using the arrow: a->b == (a, b)
. So you could write e.g.:
@select(field = myForm("selectField"), options = Seq("foo"->"Foo", "bar"->"Bar"))
But there is another helper, as shown in the documentation, to build the sequence of select options: options
, so you can rewrite the above code as:
@select(myForm("selectField"), options("foo"->"Foo", "bar"->"Bar"))
In the case your options values are the same as their label, you can even shorten the code to:
@select(myForm("selectField"), options(List("Foo", "Bar")))
(note: in Play 2.0.4 options(List("Foo", "Bar"))
doesn't compile, so you can try this options(Seq("Foo", "Bar"))
)
To fill the options from Java code, the more convenient way is to use either the overloaded options
function taking a java.util.List<String>
as parameter (in this cases options values will be the same as their label) or the overloaded function taking a java.util.Map<String, String>
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…