javascript - 在 g :remoteLink as result of javascript function 中传递参数

标签 javascript grails

在 .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>

我怎样才能做到这一点?

最佳答案

我可以建议以下 AS 解决方法

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

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

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

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

关于javascript - 在 g :remoteLink as result of javascript function 中传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10023672/

相关文章:

tomcat - 升级后的 Grails 应用程序编译但直接进入 Tomcat 404 页面

oracle - Grails 3 - 按 CLOB 值查找对象

orm - GORM继承问题

grails - Grails GORM一对多问题

javascript - 为什么 getElementById 不适用于文档以外的元素?

javascript - IE9是否支持console.log,它是一个真正的功能吗?

javascript - Electron:Dragula 不工作?

javascript - 映射数组返回逗号

javascript - 导航栏和轮播配件

spring - Grails&Spring-在resources.groovy中如何设置列表