【问题标题】:Passing params in createlink tag using jQuery使用 jQuery 在 createlink 标签中传递参数
【发布时间】:2014-04-02 17:09:14
【问题描述】:

我正在尝试做一件非常简单的事情,但我被卡住了,我觉得自己很愚蠢。 基本上我有一个这样定义的文本区域:

<textarea id="comment" name="comment" class="form-control" rows="7"></textarea>

然后我有一个 createlink 标签,我想在 params 部分中传递 textarea 的内容,所以我做了这样的事情:

<g:createLink controller="admin"
              action="book"
              id="${bookingInstance?.id}"
              params="jQuery('#comment').serialize()"/>

当然不行。 谁能给我一些建议?

非常感谢

尼贝

更新: 创建链接位于 html 标记内。像这样:

<a class="btn btn-primary btn-centered" onclick="getComment();" title="Press me" href=
<g:createLink
   controller="admin"
   action="bookAccepted"
   id="${bookingInstance?.id}"/>>
  Press me
 </a>

getComment() 函数定义如下:

function getComment() {
    window.location.href = $(this).attr('href') + '?' + $('#commet').serialize();
    return false;
}

结果我收到了这个错误信息: 为类 com.Booking 提供了错误类型的 id。预期:类 java.lang.Long,得到类 java.lang.String。 Stacktrace 如下:消息:为类 com.Booking 提供了错误类型的 id。预期:类 java.lang.Long,得到类 java.lang.String

【问题讨论】:

    标签: grails grails-2.0 grails-controller


    【解决方案1】:

    你必须用 jQuery 来做这件事。所以可能是这样的:

    <g:link controller="admin" action="book" id="${bookingInstance?.id"} onclick="return function() { window.location.href=$(this).attr('href') + '?' + $('#comment').serialize(); return false;}">My link</g:link>
    

    【讨论】:

    【解决方案2】:

    或者你可以尝试使用这样的 JS。当然,对于 ajax 调用,对我来说效果很好。

    function sendTextArea(comment) {
         var params = {"comment":comment, "id": ${bookingInstance?.id}};
         console.log(params);
         ${remoteFunction(controller: 'admin', action: 'book', params:'params', update:'div')}
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-17
      • 1970-01-01
      • 2015-12-08
      • 2013-01-25
      • 1970-01-01
      • 2016-03-20
      • 2012-10-06
      • 2017-08-11
      相关资源
      最近更新 更多