加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何在Lift(Scala)中提交表单后重新呈现页面的一部分

发布时间:2020-12-16 08:47:04 所属栏目:安全 来源:网络整理
导读:这可能是一个愚蠢的问题,但我无法弄清楚如何做到这一点. 所以我是 Scala / Lift的新手,我在 http://simply.liftweb.net/index-4.8.html#toc-Section-4.8阅读了ajax表格章节,但示例中的“RedirectTo”对我来说似乎并不是非常“ajaxian”.通常在通过ajax提交表
这可能是一个愚蠢的问题,但我无法弄清楚如何做到这一点.
所以我是 Scala / Lift的新手,我在 http://simply.liftweb.net/index-4.8.html#toc-Section-4.8阅读了ajax表格章节,但示例中的“RedirectTo”对我来说似乎并不是非常“ajaxian”.通常在通过ajax提交表单的情况下,您只需部分重新呈现相同的页面,对吧?
这就是我想要做的事情,现在我完全失败了.
在通过ajax提交表单后,如何让Lift重新呈现同一页面的一部分?

任何提示将不胜感激.谢谢.

基本上,我看起来像这样:

<div id="main" class="lift:surround?with=default;at=content">
    <h2>Welcome to your project!</h2>
    <div class="lift:Test">
        <div>
            <form class="lift:form.ajax">
                <fieldset>
                    <label for="name">Name:</label>
                    <input id="name" name="name" type=text>
                    <p></p>
                    <input id="save" type="submit" value="Save">
                </fieldset>
            </form>
        </div>
        <div>
            <span id="theName">Name</span>
        </div>
    </div>
</div>

class Test {

  def render = {
    var name = ""

    def process(): JsCmd = {
      Thread.sleep(500)

      S.notice("Entered name is: %s".format(name))
      Noop
    }

    "#theName " #> "This shall be updated with the name given in the form above" & 
    "#name" #> (SHtml.text(name,name = _) ++ SHtml.hidden(process))
  }
}

提交表单时如何更新“theName”?

解决方法

看看 http://lift.la/shtmlidmemoize-simple-ajax-updating( Example Code).有SHtml.memoize和SHtml.idMemoize自动缓存HTML代码.不确定为什么在Simply Lift书中这个例子中没有使用它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读