我将控制器中的值传递给视图,地图中的值为:
[title:[Feedback, Feedback, Suspension, Suspension],
description:[Warning Letter, Warning Letter, Suspended, Suspended],
remark:[Testing, Testing Purpose, Bikrame, Nothing Serious],
date:[2015-08-12 00:00:00.0, 2015-08-19 00:00:00.0, 2015-08-22 00:00:00.0, 2015-08-25 00:00:00.0],
semesterNo:[2, 2, 2, 3]]
因为我试图使用gsp中的键来访问地图
<g:each in="${awardsList}" var="values" status="i">
${values.getAt("title")}
</g:each>
我收到错误
No such property: title for class: java.util.LinkedHashMap$Entry.Stacktrace follows:
Message: Error evaluating expression [values.getAt("title")] on line [91]:
No such property: title for class: java.util.LinkedHashMap$Entry
答案 0 :(得分:2)
如果你的控制器返回一个地图数组作为你的awardsList:
,生活可能会更简单[[title:'Feedback', description:'Warning Letter', remark:'Testing', date:'2015-08-12 00:00:00.0',semesterNo:2],
[title:'Feedback',description:'Warning Letter', remark:'Testing Purpose', date:'2015-08-19 00:00:00.0', semesterNo:2],
[title:'Suspension',description:'Suspended', remark:'Bikrame', date:'2015-08-22 00:00:00.0', semesterNo:2],
[title:'Suspension',description:'Suspended', remark:'Nothing Serious',date:'2015-08-25 00:00:00.0',semesterNo:3]
]
然后:
<g:each in="${awardsList}" var="award">
${award.title}
</g:each>
答案 1 :(得分:0)
g:每个块中的值是Map.Entry的实例,而不是 Map 。看起来您试图遍历 Map 的列表,而是通过单个 Map 进行交互。
您可以通过将控制器返回值放在列表中来解决此问题:
[
[title:[Feedback, Feedback, Suspension, Suspension],
description:[Warning Letter, Warning Letter, Suspended, Suspended],
remark:[Testing, Testing Purpose, Bikrame, Nothing Serious],
date:[2015-08-12 00:00:00.0, 2015-08-19 00:00:00.0, 2015-08-22 00:00:00.0, 2015-08-25 00:00:00.0],
semesterNo:[2, 2, 2, 3]]
]