gson文件模板具有空变量

时间:2018-10-26 17:00:18

标签: grails json-view

我正在使用Grails 3.3.8。我有一个带模板的gson文件。

文件:

model {
    Iterable<Map<String, Object>> fileList
    Integer count
    SearchFileCommand searchFileCommand
}

    json
            {
                lastFile tmpl.fileEl(fileList ?: [])
                count count
                max searchFileCommand.max
                offset searchFileCommand.offset
                sort searchFileCommand.sort
                order searchFileCommand.sortOrder
            }

简单模板:

model {
    Map<String, Object> item
}

json {
    size item?.size
}

控制器末端的代码行是这样的:

respond([fileList: mapResult.uploadFile,count: mapResult.count, searchFileCommand: searchFileCommand], status: HttpStatus.OK, view: "searchEl")

从gson文件中,我可以看到在debug中正确填充的所有值,以及正确填充的Map列表。但是当它进入模板时,变量Map Item为空。

有什么建议吗?


我弄清楚问题出在哪里。 基本上,模板模型文件名必须是文件内部模型的名称。因此,如果模板名为_file.gson,则模板必须为:

model {
    Map<String, Object> file   <--- same name of the file
}

json {
    size item?.size
}

0 个答案:

没有答案
相关问题