我正在使用grails 2.1.1。我有一个远程函数,我想通过g:remoteFunction传递多个Java脚本变量。但是没有js变量要传递给 Controller 。我的js变量带有下划线,无法识别。谁能帮我这个忙吗?!!!这是我在下面的尝试:
我的功能>>>
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')}
}
}
最佳答案
当remoteFunction最终呈现jQuery函数时,您可以使用params选项,使用jQuery选择器或所需的Js vars或函数来包含变量。
这是一个例子。如您所见,params值只是一个字符串,但是在渲染器之后,它将被运行,因为那是js;)
<button type="button" onclick="${remoteFunction(controller: 'category', action: 'save', update: "eventsDiv",
params: '\'type=\' + myJSvar)}">
${message(code: 'default.button.save.label')}
</button>
关于javascript - 如何使用remoteFunction将JavaScript变量传递给Grails Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34389908/