在 g:remoteLink 中传递参数作为 javascript 函数的结果 [英] pass parameter in g:remoteLink as result of javascript function

查看:17
本文介绍了在 g:remoteLink 中传递参数作为 javascript 函数的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 .gsp 文件中我有 javaScript 函数

in .gsp file i have javaScript function

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

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

and in g:remoteLink I like to pass param using that function

类似于以下...

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

我怎样才能做到这一点?

How can I achieve that?

推荐答案

AS 解决方法我可以建议遵循

AS workaround I can suggest following

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

  1. change g:remoteLink to simple link

"<"a id="remove_item_button" class="btn small primary" onclick="removeItem();">- 删除项目 "<"/a>

"<"a id="remove_item_button" class="btn small primary" onclick="removeItem();">- Remove Item "<"/a>

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

Add javaScript function which will submit data via AJAX

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

function removeItem() { $.ajax({type:'POST', data:{'itemNumber':getCurrentItemNumber()}, url:'${createLink(action: 'removeItem')}', success:function (data, textStatus) { jQuery('#itemBox').html(data); }}); }

这篇关于在 g:remoteLink 中传递参数作为 javascript 函数的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆