用“变量”解析Grails参数指数 [英] Parsing Grails params with a "variable" index
问题描述
我对Grails相当陌生,我想了解如何用控制器解析某些形式的params,并使用一个计数器变量作为索引?
我有一个表单:
< g:form controller =configaction =parseReports>
< div>
< g:hiddenField name =reportName $ {allReports.indexOf(each)}value =$ {each}/>
< / g:每个>
< g:hiddenField name =reportCountSizevalue =$ {allReports.size()}/>
...
变量。
在控制器中,我有:
def reportCount = params.reportCountSize.toInteger()`
def reportCount0 = params.reportCount0.name.toString()`
这工作正常。
我想知道如何使用循环/索引:
for(counter in 0..reportCount){`
def myReport =$ {params} .reportCount $ {counter } .name.toString()}`
....
我找不到如何让myReport获得params.reportCount0.name.toString()的表单值,但使用$ {counter}变量?
任何帮助将不胜感激。
谢谢
里程。
在cotroller中试试这个。
for (0..reportCount - 1中的计数器){
String re port = params [reportName $ {counter}]
println== $ {counter} === $ {report} =====
}
$ c
pre
$ b pre
$ b $ p <$ p
你也应该在gsp页面上使用你的每个循环。
$ p> < g:each in =$ {allReports.toList()}var =eachstatus =i>
< / g:每个>
享受。
I am fairly new to Grails, and I would like to understand how to parse some form "params" with a controller, using a counter variable as an index?
I have a form:
<g:form controller="config" action="parseReports">
<div>
<g:each in="${allReports.toList()}" var="each" >
<g:hiddenField name="reportName${allReports.indexOf(each)}" value="${each}" />
</g:each>
<g:hiddenField name="reportCountSize" value="${allReports.size()}" />
...
With some hidden variables.
In the controller, I have:
def reportCount = params.reportCountSize.toInteger()`
def reportCount0 = params.reportCount0.name.toString()`
This works fine.
I would like to know how to use a loop / index:
for (counter in 0..reportCount) {`
def myReport = "${params}.reportCount${counter}.name.toString()}"`
....
I cannot find out how to get myReport to get the form value of params.reportCount0.name.toString(), but use the ${counter} variable?
Any help would be appreciated.
Thanks
Miles.
try this in cotroller.
for (counter in 0..reportCount - 1) {
String report = params["reportName${counter}"]
println "==${counter}===${report}====="
}
also you should use your each loop on gsp page like this..
<g:each in="${allReports.toList()}" var="each" status="i" >
<g:hiddenField name="reportName${i}" value="${each}" />
</g:each>
Enjoy.
这篇关于用“变量”解析Grails参数指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!