我如何将JavaScript变量传递给使用remoteFunction的grails控制器 [英] How can I pass javascript variable to grails controller using remoteFunction

查看:109
本文介绍了我如何将JavaScript变量传递给使用remoteFunction的grails控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用grails 2.1.1。我有一个远程函数,我想通过g:remoteFunction传递多个java脚本变量。但没有js变量会去控制器。我的js变量被加下划线并且不被识别。任何人都可以请帮助我吗?以下是我的尝试::

我的功能>>>

  function addNewBill(){
var orgId = $('#aaOrgIdAaOrg')。val();
var ccId = $('#costCenter')。val();
if(orgId!= null&&orgId!=null&&orgId!=&& ccId!= null&& ccId!=null&& amp ; ccId!=){
$('#ccModal')。modal('hide');
$ {remoteFunction(action:'createBill',params:[purchaseOrderId:purPoMstInstance.id,aaOrgIdAaOrg:orgId,costCenter:ccId],update:'bill')}
}
}


解决方案

由于remoteFunction最终呈现jQuery函数,因此您可以使用params选项,使用jQuery选择器或Js vars或您需要的函数来包含变量。



这是一个例子。正如你所看到的,params的值只是一个字符串,但是在渲染器之后,它会被运行,因为之后是js;)

 < button type =buttononclick =$ {remoteFunction(controller:'category',action:'save',update:eventsDiv,
params:'\'type = \' + myJSvar)}>
$ {message(code:'default.button.save.label')}
< / button>


I am working with grails 2.1.1. I have a remote function from where I want to pass more than one java script variable through g:remoteFunction. But no js variable is going to controller. My js variables are underlined and are not recognized. Can anyone please help me on this please ?!!! Here are my attempts below ::

My function >>>

function addNewBill(){
    var orgId = $('#aaOrgIdAaOrg').val();
    var ccId = $('#costCenter').val();
    if(orgId != null && orgId != "null" && orgId != "" && ccId != null && ccId != "null" && ccId != ""){
        $('#ccModal').modal('hide');
        ${remoteFunction(action: 'createBill', params: [purchaseOrderId: purPoMstInstance.id, aaOrgIdAaOrg: orgId, costCenter: ccId], update: 'bill')}            
    }
}

解决方案

As remoteFunction finally renders a jQuery function, you can use the params option, to include your variables using jQuery selectors or the Js vars or functions you need.

Here is an example. As you can see, the params value is just an string, but after renderer, it will be run cause after that is js ;)

<button type="button" onclick="${remoteFunction(controller: 'category', action: 'save', update: "eventsDiv",
   params: '\'type=\' + myJSvar)}">
         ${message(code: 'default.button.save.label')}
</button>

这篇关于我如何将JavaScript变量传递给使用remoteFunction的grails控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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