grails多项选择:值未存储在相关对象中 [英] grails multiple select: values are not stored in related object
问题描述
我有多项选择,如下所示:
I have a multiple select as follows:
<g:select name="receiptItems" from="${HealthService.findAllByDoctor(Doctor.findBySecUser(new ReceiptController().getCurrentlyLoggedUser()))}"
multiple="multiple" optionKey="id"
optionValue="${{it.healthServiceType.healthService}}"
size="5" value="${receiptInstance?.healthServices*.id}" class="many-to-many"
onchange="${remoteFunction(
controller: 'Receipt',
action: 'sumReceiptItems',
params: '\'receiptItemsSelected=\' + jQuery(this).val()',
onSuccess: 'updateTotalAmount(\'totalAmount\', data, \'00000\')')}"/>
每次选择后,使用remoteFunction
,将调用控制器中的方法进行一些计算并更新totalAmount字段.它工作得很好,但是,当调用save
方法时,healthServices
字段为null ...,我不明白为什么.
我也尝试过
After each selection, with the remoteFunction
, a method from controller is called to do some calculation and update the totalAmount field. It works well but, when save
method is called, healthServices
field is null...and I don't understand why.
I've tried also with
receiptInstance?.healthServices.collect{it.id}
但是我有相同的结果. 有什么建议吗?
but I have the same result. Any suggestion?
推荐答案
您将选择标签命名为" receiptItems ",因此在Controller中检查该参数,然后将其添加到 receiptInstance :
You named the select tag "receiptItems", so in the Controller inspect that parameter and then add it to the receiptInstance:
params?.receiptItems?.each {
def service = HealthService.get(it)
receiptInstance.addToHealthServices(service)
}
这篇关于grails多项选择:值未存储在相关对象中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!