我有我的網頁上下面的AJAX形式:斯卡拉電梯 - AJAX形式工作不正常
<form class="lift:form.ajax">
<div class="lift:StreamInput">
<input type="hidden" name="path" />
<input type="hidden" name="user" />
<input type="hidden" name="level" />
<input type="hidden" name="room" />
</div>
<input type="submit" value="" />
</form>
每個輸入字段值是通過調用DB片段設置。
當表單提交它的意思的值發送到以下幾點:
import comet.StreamServer
object StreamInput {
def render = {
var path = ""
var user = ""
var level = ""
var room = ""
def process(): JsCmd = {
val message = comet.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 = _)
}
}
從那裏,你可以看到,它應該運行的工藝方法,從表單數據構建「StreamItem」這是包含在StreamServer然後發送所述對象到所述StreamServer更新監聽器的情況下的類:
case class StreamItem(user: String, path: String, level: String, room: String)
class StreamComet extends CometActor with CometListener {
private var streams: List[StreamItem] = Nil
def registerWith = StreamServer
override def lowPriority = {
case v: List[StreamItem] =>
streams = v;
reRender();
}
def addStreams(): String = {
var script = ""
streams.foreach{stream =>
script += """
STREAMMOD.stream_view.add_stream({
path : '""" + stream.path + """',
level : '""" + stream.level + """'
})
"""
}
return script
}
def render = {
OnLoad(JsRaw(
addStreams()
).cmd)
}
}
object StreamServer extends LiftActor with ListenerManager {
private var streams: List[StreamItem] = Nil
def createUpdate = streams
override def lowPriority = {
case StreamItem(user, path, level, room) => {
streams :+= StreamItem(user, path, level, room);
updateListeners()
}
}
}
最終的結果應該是一個javascript函數被調用whcih發送要顯示在頁面上的數據。
當提交數據時,雖然數據似乎沒有得到那麼多,但它只是提交表單,然後什麼也沒有發生。
我錯過了什麼?任何幫助非常感謝,在此先感謝:)
http://simply.liftweb.net/index-4.8.html#toc-Section-4.8 – Debilski
好吧我已經找到了具體的問題,似乎表單中的值沒有正確傳遞給過程方法在StreamInput中。我錯過了什麼或錯誤地做了什麼,這意味着這些值會丟失? – jhdevuk
我認爲主要的問題是沒有指定'process'方法的回調。 – Debilski