SCALA Lift - AJAX形成多个值

时间:2011-10-24 16:59:29

标签: ajax scala lift

我有以下表格:

<form class="lift:form.ajax">
    <input type="hidden" class="lift:StreamIn" id="path" value="PATH" />
    <input type="submit" value="" />
</form>

其中包含:

object StreamIn {

    def render = SHtml.onSubmit(path => {

        StreamServer ! path

    })

}

case class StreamItem(user: String, path: String, level: String, room: String)

object StreamServer extends LiftActor with ListenerManager {

    private var streams: List[StreamItem] = Nil

    def createUpdate = streams

    override def lowPriority = {

        case stream: String if stream.length > 0 =>

            streams :+= StreamItem("James", stream, "_1", "demo-room");
            updateListeners()

    }

}

我正在寻找的是一种将多个值传递给具有多个输入的StreamServer的方法。

因此,不是静态字符串值“James”,“_ 1”和“demo-room”,它们将从表单中传递。

提前感谢您的帮助,非常感谢:)

1 个答案:

答案 0 :(得分:3)

你的ajax表单上有几个输入字段可以吗? 如果是这样,那怎么样:

<form class="lift:form.ajax">
  <div class="lift:StreamIn">
    <input type="text" name="path" />
    <input type="text" name="user" />
    <input type="text" name="level" />
    <input type="text" name="room" />
    <input type="hidden" name="hidden" />
  </div>
</form>

<强>更新

object StreamIn {
  case class StreamItem(user: String, path: String, level: String, room: String)
  def render = {
    var path= ""
    var user= ""
    var level= ""
    var room= ""
      def process(): JsCmd= {
        val message= StreamItem(user, path, level, room)
        StreamServer ! message
      }

    "name=path" #> SHtml.onSubmit(path= _ ) &
    "name=user" #> SHtml.onSubmit(user= _ ) &
    "name=level" #> SHtml.onSubmit(level= _ ) &
    "name=room" #> SHtml.onSubmit(room= _) &
    "name=hidden" #>  SHtml.hidden(process)

  }
}

并更改lowPriority:

override def lowPriority = {
  case StreamItem(userIn, pathIn, levelIn, roomIn) => {
    streams :+= StreamItem(userIn, pathIn, levelIn, roomIn);
    updateListeners()
  }

}

我错过了一些}但我希望你能得到这个想法,你可以省略一些字段,如房间和关卡,如果你有它们,你可以使用RequestVar访问它们。

您可以在Simply Lift Book

上的ajax表单上阅读更多内容

希望有所帮助