score:0

First, you need to know how to generate HTML from your Board class. There are two choices:

  1. from server, scala.XML

  2. from client, javascript

Then, create an ajax server-side function which you can call from client:

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>
}

At last, you should have a client function "renderBoard(b)" to render you board on your page. and when the client click to move, call "moveIt(x, y)"


Related Query

More Query from same tag