处理多选不带选择 [英] handling multi-select with no selection
问题描述
我在我的应用程序中使用了 grails generate-all
。 作者
视图有一个允许多个 Book
实例的多重选择:
I used grails generate-all
on my application. The Author
view has a multi-select which allows for a number of Book
instances:
<g:select multiple="true" ... />
但是,如果我编辑现有的作者
谁拥有15本书中的5本(多选显示15本书,5选),取消选择所有书籍并点击保存,作者
仍然保留他们的5本书。从我所知道的情况来看, Author
的form - books属性没有任何书籍输入不会被更改。
However, if I edit an existing Author
who owns 5 out of total 15 books (the multi-select shows 15 books, 5 selected), unselect all books and click save, the Author
still keeps their 5 books. From what I can tell, no book input from the form - books property of Author
don't get changed.
现在,我可以在我的控制器中进行测试(如下所示):
Now, I can test for this in my controller (something like this):
if (params?.books.size() < 1) {
authorInstance.books = []
}
是这样做的,或者有更好的方法吗?
Is this the way to do it, or is there a better way?
推荐答案
我见过的大多数示例都使用:
Most examples I've seen use:
authorInstance.books.clear()
这篇关于处理多选不带选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!