Grails复选框处理 [英] Grails checkbox handling
问题描述
假设我有这个scenerio:
Let's say, i have this scenerio:
但是我有数百个这样的复选框,我需要在提交表单后同时处理所有内容。然后我需要保存到BD基于哪些框被检查和每个块的ID
But let's say i have hundreds of those checkBoxes, which i need to handle everything at same time after submiting a form. I then will need to save to the BD something based on which boxes are checked, and the id of each block
所以,我需要这个:
a)一种方法来知道哪些复选框被选中,在其中几百个
b)每个复选框应该与一个id链接,因此一个具体的动作
a) a way to know which checkboxes are checked, within hundreds of them b) each checkbox should be 'linked' with an id which im gona pass, so that a specific action will be performed.
我有一个< g:each>
标签给我写了整个表,数据库。我非常感谢任何帮助,
感谢高级,RR
I have a <g:each>
tag writing me the whole table, reading values from the DB. I would appreciate any help with this,
Thanks in advanced, RR
推荐答案
在你的gsp你需要显示所有复选框:
In your gsp you need to display all the checkboxes:
<g:each in="${model}" status="i" var="invoiceItem">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
<td>
<g:checkBox name="invoiceItem_${i}"/>
</td>
</tr>
</g:each>
在控制器操作中,您需要将所选的复选框映射到您的域对象
In the controller action you need to map the selected checkboxes to your domain objects
List invoiceList = session.invoiceList
params.each {
if (it.key.contains("invoiceItem_")){
if (it.value.contains("on")){
InvoiceItem invoiceItem = invoiceList.get((it.key - "invoiceItem_") as Integer)
}
}
}
这篇关于Grails复选框处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!