如何在远程功能中传递参数

时间:2013-09-13 11:28:41

标签: javascript grails

我有一个带远程功能的javascript函数,,,在那个远程功能我想通过map有参数,我想在控制器动作中使用那个地图变量,我不知道如何在ramotefunction和params中传递它在特定的控制器动作中使用它......

jQuery(document).ready(function(){
 alert("checking for checkbox");
 var countryId = document.getElementById("countryId").value;
    jQuery('#groupdelete').on('click', function(){
        var names = {};
        alert("*********");
        jQuery('input:checked').each(function() {
            alert(jQuery(this).attr("id"));
            if(jQuery(this).attr("id")) {
            var id=jQuery(this).attr("id")
            var costId = "c"+id
            var ntb = document.getElementById(costId).value;
            alert(ntb);
            names[id] = ntb;
            }   
        });
        alert(names[1]);
    })


    ${remoteFunction(action:'addLabServiceToCountry', controller:'country', params:'\'names=\'+names')}

})

params:'\'names=\'+names' which is not working properly, how to pass map variable in params of remotefunction and in contoller action how to access that.

1 个答案:

答案 0 :(得分:0)

试试这个:

${remoteFunction({action: "addLabServiceToCountry", controller: "country", params: names});

然后在remoteFunction()中,您需要遍历params以获取所有映射的名称。

或者您可以将names转换为字符串:

var namesStr = names.join(',');

然后传递字符串:

${remoteFunction({... , params: namesStr});