提升自动填充更改页面内容

时间:2012-01-09 11:38:54

标签: autocomplete lift widget

我使用自动完成小部件在liftScreen中向用户显示所需的输入。我需要使用所选的自动填充选项更改页面内容。

是否可以使用自动完成小部件?

如果是,请发布一个例子。

1 个答案:

答案 0 :(得分:2)

以下是Autocomplete和Ajax的示例:

/*Create a ValueCell to update*/
val cell = ValueCell("")

/* Do a basic ajaxText */
val nameAjax = SHtml.ajaxText(cell.get, s=>{ cell.set(s); Noop})

/* Make attributes out of it */
val attrs: Seq[(String,String)] = nameAjax.attributes.toList.map{md => (md.key,md.value.text)}

/* Do the basic autocomplete with your attibutes */
def query(s:String):List[String] /*Do the query to get the desired autocomplete values */
def buildQueryName(current: String, limit: Int): Seq[String] = {
  if (current.length == 0) Nil
  else query(current).take(limit) /*query representing
}
private def processResult(s : String) {}

/* Function to render the autocomplete box */
def autoCompleteBox = AutoComplete("", buildQueryName _, processResult _ , attrs:_* )

/* function to render the dynamic part */
def dynamicPart = WiringUI.apply(cell)(createDynamicPart)

def createDynamicPart(value:String)(ns:NodeSeq):NodeSeq ={
  <h3> value selected: {value} </h3>
}