免责声明:我是以下库的作者。
我认为lift-combobox可以实现您想要的,因为它具有让用户即时创造价值的功能。它使用select2 jQuery 插件,因此您将对下拉菜单有一个很好的外观和感觉。
例如,如果你需要获取用户创建的值,它会简单如下,注意我们通常使用Option[T]
来表示该值可能不呈现,例如,用户可能没有在下拉菜单中选择任何项目全部:
var friend_name: Option[String] = None
val friendsMenu = new ComboBox(
default = None,
allowCreate = true
) {
// This is where you build your combox suggestion
override def onSearching(term: String): List[ComboItem] = {
val names = List(
ComboItem("f1", "Brian"), ComboItem("f2", "Alice"),
ComboItem("f3", "Luke"), ComboItem("f4", "Smith"),
ComboItem("f5", "Brandon")
)
names.filter(_.text.contains(term))
}
override def onItemSelected(selected: Option[ComboItem]): JsCmd = {
friend_name = selected
// The returned JsCmd will be executed on client side.
Alert("You selected:" + selected)
}
// What you want to do if user added an item that
// does not exist when allowCreate = true.
override def onItemAdded(text: String): JsCmd = {
friend_name = Some(text)
}
}
"#bdayReminder" #> friendsMenu.combobox