我正在尝试向 Grails 命令对象/表单中的 map 添加另一层嵌套。命令对象当前有一个名为 otherData 的 Map。
Map otherData
表单的字段具有如下所示的命名约定,提交时会生成 map 。
<input id="birthDate" name="otheData[birthDate]" type="hidden" value="">
<input id="county" name="otheData[county]" type="hidden" value="">
然后在表单提交时在我的 Controller 中,如果有任何数据要执行搜索,我会将其绑定(bind)到另一个 map 。
if(otherData) {
_searchCriteria.otherData = otherData
}
我基本上想要另一层不确定性,这样我就可以检查另一个关键路径并对数据执行正确的操作。下面的例子:
if(searchCriteria otherData.relativeDate) {
....
} else if(searchCriteria otherData.absoluteDate) {
....
}
我试图对输入的名称进行编码以表示嵌套映射,但它没有在我的 Controller 中创建嵌套映射。
<input id="birthDate" name="otheData[relative:[birthDate]]" type="hidden" value="">
它正在生成带有 keypath 的 map
otherData.relative:[birthDate
有没有办法在结构中添加另一层?
最佳答案
试试 "otheData.relative.birthDate"
而不是 otheData[relative:[birthDate]]
关于html - Grails 表格,嵌套 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47245668/