gpt4 book ai didi

ajax - grails:具有多个选择的remoteFunction

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

我需要将remoteFunction指令与多项选择一起使用。
选择如下:

<g:select name="receiptItems" from="${myproject.ReceiptItem.list()}"
multiple="multiple" optionKey="id" optionValue="description" size="5"
value="${receiptInstance?.receiptItems*.id}" class="many-to-many"
onchange="${remoteFunction(
controller: 'Receipt',
action: 'sumReceiptItems',
params: '\'receiptItemsSelected=\' + this.value',
onSuccess: 'updateTotalAmount(\'totalAmount\', data, \'00000\')')}"/>

我在Receipt Controller 中有 sumReceiptItems操作,该操作接受参数 receiptItemsSelected并使用它来更新另一个文本字段。

问题是 this.value仅给我一个选定的值,即最后一个选定的值。我需要将select中所有选定的值传递给 Controller ​​。
我该怎么做?

感谢您的宝贵帮助

最佳答案

只需使用jQuery's val()而不是this.value,即可获取所有选定项:

params: '\'receiptItemsSelected=\' + jQuery(this).val()'

请注意,如果尚未在项目中使用jQuery,则必须导入它。如果您正在使用最新的Grails版本,则只需在 <r:require module='jquery' />部分中使用 <head>即可完成此操作。

关于ajax - grails:具有多个选择的remoteFunction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17110786/

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