繁体   English   中英

在 g:remoteLink 中传递参数作为 javascript function 的结果

[英]pass parameter in g:remoteLink as result of javascript function

in.gsp 文件我有 javaScript function

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

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

像跟随...

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

我怎样才能做到这一点?

作为解决方法我可以建议以下

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

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

  2. 添加 javaScript function 将通过 AJAX 提交数据

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM