[英]Grails remoteFunction AJAX function in a GSP, accessing variable to use for params
我想在复选框内的remoteFunction中 动态设置参数 。 我尝试了很多不同的组合,下面将显示几个示例,但我只收到如下的错误...
所以基本上是我的理论,在这种方法的范围内,不知道eventInstance是什么
在FireBug错误控制台中,我收到ReferenceError: eventInstance is not defined
Test Combination 1
<g:checkBox name='completed' value="${eventInstance.completed}"
onclick="${remoteFunction(action:'update', id:eventInstance.id, params:'\'id=\' + eventInstance.id+\'&version=\' + eventInstance.version' , onComplete: "tester()" )}" />
Test Combination 2
<g:checkBox name='completed' value="${eventInstance.completed}" evt="${eventInstance}"
onclick="${remoteFunction(action:'update', id:eventInstance.id, params:"[version=evt.version, editType='occurrence', title=evt.title, startTime=start, endTime=end, isRecurring=evt.isRecurring, completed='true']", onComplete: "tester()" )}" />
如果手动输入即对数据进行硬编码,则此方法有效,但这没有用。 我只是无法找到答案的愚蠢的东西:(
可以正常工作...似乎有些奇怪,您不能使用grails变量,即从控制器发送来在GSP中使用的变量
相反......你必须变量保存到一个JavaScript变量。
因此,对于我想从eventInstance
中使用的每个变量,以在params
即id,version)中使用,包含在其中的任何其他字段都只是执行以下操作:
<script type="text/javascript">
function tester() {
$('#calendar').fullCalendar('refetchEvents');
}
var test0 = ${eventInstance.id};
var test1 = ${eventInstance.version};
var test3 ='${eventInstance.title}';
var test4 = '${start}';
var test5 = '${end}';
var test6 = ${eventInstance.isRecurring};
alert(test0 + test1 + test3 + test4 + test5 + test5 +
</script>
然后在remoteFunction
的params部分中引用这些变量,如下所示:
<g:checkBox name='completed' value="${eventInstance.completed}"
onclick="${remoteFunction(action:'update', id:eventInstance.id, params:'\'id=\' + test0+\'&version=\' + test1+\'&editType=\'+"occurrence"', onComplete: "tester()" )}" />
不知道这是我的方法中的某种错误还是仅是某种错误,但是我尝试了每种可能的组合,并且似乎是我唯一能解决的解决方案
这可以帮助您,
onchange="${remoteFunction(asynchronous: false, controller: 'mycontroller', action: 'remoteMethod', params: '\'p1='+params?.p1+'&p2=less&p3=\'+ this.value', update: 'remoteDiv')}"
尝试这个。
这可以帮助您,
onchange="$
{
remoteFunction(asynchronous: false,
controller: 'mycontroller',
action: 'remoteMethod',
params: '\'p1='+params?.p1+'&p2=less&p3=\'+ this.value', update: 'remoteDiv')}"
尝试这个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.