【问题标题】:pass parameter in g:remoteLink as result of javascript function作为 javascript 函数的结果,在 g:remoteLink 中传递参数
【发布时间】:2012-04-18 21:38:55
【问题描述】:

在 .gsp 文件中我有 javaScript 函数

<script type="text/javascript">
 function getCurrentItemNumber(){
        return document.getElementById('item_itemNumber').innerHTML.substr(6);
    }
</script>

在 g:remoteLink 中,我喜欢使用该函数传递参数

类似以下...

<g:remoteLink id="remove_item_button" action="removeItem" update="itemBox"
            params="[itemNumber:getCurrentItemNumber()]">- Remove Item</g:remoteLink>

我怎样才能做到这一点?

【问题讨论】:

    标签: javascript grails


    【解决方案1】:

    我可以建议以下解决方法

    1. 将 g:remoteLink 更改为简单链接

      "- 删除项目 ""/a>

    2. 添加通过 AJAX 提交数据的 javaScript 函数

      函数 removeItem() { $.ajax({type:'POST', 数据:{'itemNumber':getCurrentItemNumber()}, url:'${createLink(action:'removeItem')}', 成功:函数(数据,文本状态){ jQuery('#itemBox').html(数据); }}); }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-28
      相关资源
      最近更新 更多