gpt4 book ai didi

ajax - GSP中的Grails remoteFunction AJAX函数,访问用于参数的变量

转载 作者:行者123 更新时间:2023-12-02 15:11:33 26 4
gpt4 key购买 nike

我想在复选框内的 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变量,即从 Controller 发送以在GSP中使用的变量

相反,您必须将变量保存到JavaScript变量中。

因此,对于我想从eventInstance中使用以在params中使用的每个变量(即ID,版本),包含在其中的任何其他字段都只是执行以下操作:

<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()" )}" />

不知道这是我的方法中的某种错误还是仅是某种错误,但是我尝试了每种可能的组合,并且似乎是我唯一能解决的解决方案

关于ajax - GSP中的Grails remoteFunction AJAX函数,访问用于参数的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14362897/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com