I need help with the example in section 10.6 A Recap, please.
I created a project to run the code and expected that when I search
for a name in the list I would see the name displayed in the
"items_list" div. However, instead of seeing the name displayed in the
list, I see "JsExp(it)" in the list.
For example, when I search for "d" I see two "JsExp(it)" entries in
the list (I assume one is for "derek" and the other is for "dave").
How can I get the names to display in the list, instead of the
"JsExp(it)"?
Many thanks in advance for your help.
Background Info
I am using lift version 2.4-M3 and scala version 2.9.0-1.
Book Reference:
http://exploring.liftweb.net/master/index-10.html
(section 10.6 at end of page).
Here is the relevant code from my project:
1. search.html
<lift:surround with="default" at="content">
<lift:Hello.ajaxian>
<text:show/>
</lift:Hello.ajaxian>
<div id="items_list" style="width: 300px; height: 100px; overflow:
auto; border: 1px solid black;">
</div>
</lift:surround>
2. Hello.scala snippet
class Hello {
val names = "marius" :: "tyler" :: "derek" :: "dave" ::
"jorge" :: "viktor" :: Nil
def ajaxian(html: Group) : NodeSeq = {
bind("text", html,
"show" -> ajaxText("Type something", {value => {
val matches = names.filter(e => e.indexOf(value) > -1)
SetHtml("items_list", NodeSeq.Empty) &
JsCrVar("items", JsArray(matches.map(Str(_)):_*)) &
JsCrVar("func", Jx(<ul>{
JxMap(JsVar("it"), Jx(<li><a
href="">{JsVar("it")}</a></li>))}</ul>).toJs) &
(ElemById("items_list") ~> JsFunc("appendChild",
Call("func", JsVar("items"))))
}})
)
}