SCALA Lift - 访问 AJAX 表单值

发布于 2024-12-12 04:07:55 字数 1162 浏览 0 评论 0原文

我有以下表单:

<form class="lift:form.ajax">
<div class="lift:StreamInput">
    <input type="hidden" name="path" value="test" />
    <input type="hidden" name="user" value="james" />
    <input type="hidden" name="level" value="_1" />
    <input type="hidden" name="room" value="demo" />
    <input type="hidden" name="hidden" value="true" />
</div>
<input type="submit" value="" />
</form>

转到:

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 = _) &
        "name=hidden" #>  SHtml.hidden(process)

    }

}

但是,当我提交表单时,传递给 process 方法的值是空的。我错过了什么会导致他们丢失?

感谢您提前提供任何帮助:)

I have the following form:

<form class="lift:form.ajax">
<div class="lift:StreamInput">
    <input type="hidden" name="path" value="test" />
    <input type="hidden" name="user" value="james" />
    <input type="hidden" name="level" value="_1" />
    <input type="hidden" name="room" value="demo" />
    <input type="hidden" name="hidden" value="true" />
</div>
<input type="submit" value="" />
</form>

Which goes to:

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 = _) &
        "name=hidden" #>  SHtml.hidden(process)

    }

}

However when I submit the form the values passed to the process method are empty. What am I missing that would cause them to be lost?

Thanks for any help in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

胡大本事 2024-12-19 04:07:55

我现在无法测试它,但可能是 SHtml.onSubmit 在 Ajax 上下文中不起作用。如果您查看文档,就会发现 SHtml.onSubmit 仅在非 Ajax 示例中使用。 Ajax 示例使用 SHtml.text 将回调绑定到文本输入字段。

I’m not able to test it right now but it could be that SHtml.onSubmit does not work in an Ajax context. If you look at the documentation, SHtml.onSubmit is only used in the non-Ajax example. The Ajax examples use SHtml.text to bind a callback to the text input fields.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文