斯卡拉,电梯| SHtml.select - 如何从数据库中放入列表

时间:2012-07-23 11:40:48

标签: forms scala lift

我正在尝试将数据库中的一些值放入(select):

val kateg = Kategoria.findAll.map(a => (a.id.toString , a.nazwa))

接下来是形式:

 bind("entry", xhtml,
        "kateg" -> SHtml.select(kateg, Empty, select ), 
       "temat" -> SHtml.text(temat, temat = _),
        "opis" -> SHtml.textarea(opis, opis = _, "cols" -> "80", "rows" -> "8"),
        "submit" -> SHtml.submit("Add", processEntryAdd))

然后我有错误:

Description Resource    Path    Location    Type
type mismatch;  found   : List[(java.lang.String, a.nazwa.type) for 
Some { val a: code.model.Kategoria }]  
required: Seq[(String, String)] Forma.scala 
/lift-todo-mongo/src/main/scala/code/snippet    
line 51 Scala Problem

任何想法?感谢

1 个答案:

答案 0 :(得分:3)

SHtml.select(..)允许您选择String值。 它需要一个Seq of tuples(值:String,Key:String

在这种情况下,你可能需要写:

val kateg = Kategoria.findAll.map(a => (a.id.toString , a.nazwa.is))

如果 nazwa 是Kategoria实体的MappedString字段。 即 kateg 的类型应为Seq[(String, String)]

但我建议您使用SHtml.selectObj来选择Kategoria实体而不是String name value:

val kateg: Seq[(Kategoria, String)] = Kategoria.findAll.map(a => (a, a.nazwa.is))
SHtml.selectObj[Kategoria](kateg, Empty, (k: Kategoria) => { .. /* assign */ .. })