我有多个选择,如下所示:

<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,将调用 Controller 中的方法进行一些计算并更新totalAmount字段。它工作正常,但是,当调用save方法时,healthServices字段为null ...而且我不明白为什么。
我也尝试过
receiptInstance?.healthServices.collect{it.id}

但我有相同的结果。
有什么建议吗?

最佳答案

您将选择标签命名为“ receiveItems ”,因此在Controller中检查该参数,然后将其添加到receiveInstance:

params?.receiptItems?.each {
    def service = HealthService.get(it)
    receiptInstance.addToHealthServices(service)
}

10-06 01:23