首先,你需要知道如何从你的板子类HTML。 有两种选择:
从服务器,scala.XML
从客户端的JavaScript
然后,创建一个Ajax服务器端功能,您可以从客户端调用:
def render = {
import JsCmds._
var board = initBoard()
def moveAction(s: String): JsCmd = {
val moveXY = parseXY(s) // s should be like "{x: 1, y: 2}"
board = move(board, moveXY) // your logic here
val newBoardToSend = boardToCmd(board) // generate board HTML or json here
Call("renderBoard", newBoardToSend) // call the client-side render function
}
val script = S.fmapFunc(S.contextFuncBuilder(moveAction _)) { funcName => {
val func = JsRaw("'" + funcName + "='") + Call("encodeURIComponent", LiftRules.jsArtifacts.jsonStringify(JsRaw("{x:x,y:y}")))
JsCmds.Function(
"moveIt", // the js function name you will call
"x" :: "y" :: Nil,
SHtml.makeAjaxCall(func).cmd
)
}} // generate a client ajax function: function moveIt(x, y)
yourRenderXml ++ <tail>{JsCmds.Script(script)}</tail>
}
最后,你应该有一个客户端函数“re nderBoard(b)“让你登上你的网页。当客户点击移动时,调用“moveIt(x,y)”
嘿iron9light,非常感谢!我能联系你多一点帮助吗?目前,Lift对我非常困惑。我的电子邮件是:[email protected] – user1137701 2012-01-10 13:16:26
在此处询问或在[论坛](https://groups.google.com/forum/#!forum/liftweb) – iron9light 2012-01-11 02:28:52