5

可能重复:
在 g:remoteLink 中传递参数作为 javascript 函数的结果

我正在尝试调用由按钮的 onclick 触发的 remoteFunction 调用,但单击不会调用该函数。我已经使用警报启动测试了 onlick 命令并调用了该函数。这是我的代码。

<input type="button" onclick="exportList()" value= "Export"/>

function exportList(){

            var profile= document.getElementById('dropdown').value
            ${remoteFunction(controller: 'profile' , action:'export', params: "'profile=' + profile")}  


}

当我取出参数和 var 配置文件时,仍然没有调用该函数...我的控制器和操作已正确命名,所以我不知道为什么会出现此错误。如果您能提供帮助,请提前致谢!

4

2 回答 2

3

JoeCortopassi 是正确的——你不能${remoteFunction...}直接在 javascript 中使用 grails 构造。我已经像这样使用 Jquery 完成了这项工作:

function exportList() {
    var profileToUse = document.getElementById('dropdown').value
    jQuery.ajax({
        url: "/youApp/profile/export",
        type: "POST",
        data: {profile: profileToUse}
    });
}
于 2012-06-14T22:32:21.690 回答
2

我不知道这应该做什么,但它看起来很糟糕

${remoteFunction(controller: 'profile' , action:'export', params: "'profile=' + profile")} 

你确定要说var{remoteFunction()}吗?原因$只是一个变量。如果您使用的是 jQuery,那就更没有意义了。此外,您传递的内容remoteFunction()看起来应该是对象,但没有包含在{}

于 2012-06-14T21:13:40.933 回答