私はそれがJavascriptに囲まれたコードをコンパイルすると仮定しますが、コードはどのように実行されるのではなくコンパイルされますか?例えば、からこのコードは単純にリフト:JsCmdはどのようにLiftで動作しますか?
object AjaxExample {
def render = {
// state
var name = ""
var age = "0"
val whence = S.referer openOr "/"
// our process method returns a
// JsCmd which will be sent back to the browser
// as part of the response
def process(): JsCmd= {
// sleep for 400 millis to allow the user to
// see the spinning icon
Thread.sleep(400)
// do the matching
asInt(age) match {
// display an error and otherwise do nothing
case Full(a) if a < 13 => S.error("age", "Too young!"); Noop
// redirect to the page that the user came from
// and display notices on that page
case Full(a) => {
RedirectTo(whence,() => {
S.notice("Name: "+name)
S.notice("Age: "+a)
})
}
// more errors
case _ => S.error("age", "Age doesn't parse as a number"); Noop
}
}
// binding looks normal
"name=name" #> SHtml.text(name, name = _, "id" -> "the_name") &
"name=age" #> (SHtml.text(age, age = _) ++ SHtml.hidden(process))
}
}
私はこの質問にどのような種類のJavaScript文字列を組み込みますか? –
これは、あなたのコードが束になっているので複雑です。基本的に 'window.location'リダイレクトや、関連する要素に対するさまざまな' innerHTML'呼び出しです。 – pr1001