使用更新功能在远程功能后调整其他选择的值

问题描述 投票:0回答:1

我正在尝试在onChange中发生的远程功能之后,在“更新”或“ onSuccess”中更改单独的“ g:select”的选定值。

GSP代码:

<g:select name="mainSelect"
                                  id="mainSelect"
                                  from="${mainSelect}"
                                  value="${mSelect}"
                                  optionKey="key"
                                  optionValue="value"
                                  onchange="${remoteFunction (
                                            controller: 'mainController',
                                            action: 'checkValue',
                                            params: '\'value=\' + this.value + \'&value2=\' + otherSelect.value',
                                            onSuccess: '$("#otherSelect").val(data)',
                                  )}"
                                  noSelection="['': '']"/>
<g:select name="otherSelect"
                              id="otherSelect"
                              from="${notimportant}"
                              value="${notimportant2}"
                              optionKey="key"
                              optionValue="value" />

remoteFunction的“ checkValue”依赖于一些变量来呈现“ Y”或“ N”,我已经注销了它,知道这肯定是每次返回的内容。在这之后,我似乎无法下拉列表进行更改。我的帖子没有返回任何错误,我仅会收到错误,具体取决于onSuccess或更新中的内容。

我已经尝试了多种方法,例如:

onSuccess: '$("#otherSelect").val(data)',

update: 'otherSelect'
jquery grails
1个回答
0
投票

http://docs.grails.org/3.0.0.M1/ref/Tags/remoteFunction.html

onSuccess(可选)-成功时要调用的JavaScript函数

只需制作一个JS函数来插入onSuccess,因为直接Javascript不想工作。代替上面的onSuccess:

onSuccess: 'functionForSelect(data)',

功能:

function functionForSelect(option)
{
  document.getElementById("otherSelect").value = option;
}
© www.soinside.com 2019 - 2024. All rights reserved.