如何获取grails中的复选框列表 [英] How to get a list of checked boxes in grails
问题描述
在grails中,我想获得一个选中复选框的列表。
我有复选框列表,但我的问题是两个:
In grails, I am trying to get a list of checked check boxes. I have the list of check boxes, but my issues are two:
1)当我点击列表中的单个项目,然后单击提交只得到值开。如果我点击多个复选框项目,我会得到这样的:
1) when I click on a single item in the list and click submit - I only get the value "on". If I click more than one check box item, I get something like this:
[Ljava.lang.String;@5a37f9f7
2)。
以下是gsp中的复选框的代码:
Here is my code for the check boxes in the gsp:
<g:form action="submitForm">
<ul class="columns3">
<g:each in="${name}" var="fileName" >
<g:checkBox value="${false}" name="${ 'fileName'}" /> ${fileName.replaceFirst(~/\.[^\.]+$/, '')}<br>
</g:each>
</ul>
<br>
<br>
<g:submitButton name="Submit"/>
</g:form>
,这里是控制器代码(groovy):
and here is the controller code (groovy):
class Read_dirController {
def index() {
def list = []
def dir = new File("/home/ironmantis/Documents/business/test_files")
dir.eachFileRecurse (FileType.FILES) { file ->
list << file
}
list.each {
println it.name.replaceFirst(~/\.[^\.]+$/, '')
}
render(view: "index", model: [name:list.name])
params.list('fileName')
}
def displayForm() { }
def submitForm(String fileName) {
render fileName
//render(view: "tests_checked", fileName)
}
}
复选框,但我不断收到异常错误。
I tried to bind an id to the check boxes, but I keep getting an exception error.
任何帮助,你可以给我真正的赞赏;我是grails新手。
Any help you can give I truly appreciate it; I am new to grails.
ironmantis7x
ironmantis7x
推荐答案
def submitForm() {
def values = request.getParameterValues("fileName")
//here values contains string array which are selected in checkbox
}
这篇关于如何获取grails中的复选框列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!