How to call the function generated by Jx

2 views
Skip to first unread message

Guofeng Zhang

unread,
Nov 17, 2010, 10:12:05 PM11/17/10
to The Lift Book
I reading Exploring Lift, and have some questions confused me. I am
new to Lift, this confuse me for days, thanks for your help.

(1) In the section "XML and JavaScript", you have a sample code:
val div = Jx(<div>Hi there</div>)
This will generate the following function:
function(it) {
var df = document.createDocumentFragment();
var vINIJ1YTZG5 = document.createElement('div');
df.appendChild(vINIJ1YTZG5);
vINIJ1YTZG5.appendChild(document.createTextNode('Hi there'));
return df;
}

How to write a code in Scala so that the client (browser) could invoke
the function?

(2) there is the following code segment:
var list = {
persons: [
{name: "Thor", race: "Asgard"},
{name: "Todd", race: "Wraith"},
{name: "Rodney", race: "Human"}
]
}
I think this should be the JavaScript code in the HTML file, am I
right?

Following the above, there is the following code segment:
def renderPerson =
Jx(<li class="item_header"> {JsVar("it", "name")}
is {JsVar("it", "race")}</li>)
Jx(<ul>{JxMap(JsVar("it.persons"), renderPerson)}</ul>)

I cannot understand how the value of the list variable is passed, that
is, why it.persons will reference to values of list variable?

Reply all
Reply to author
Forward
0 new messages