在Gson中渲染少量模型 [英] Rendering few models in gson
本文介绍了在Gson中渲染少量模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将少量对象发送到gson渲染视图? 我尝试在控制器中使用:
Is it possible to send few objects into gson rendering view? I tried to use in controller:
respond trainings, [status: OK, view:"trainingsByClients", model: [myVariable: "test", anotherVariable: 123]]
并在 gson视图中:
model {
Iterable<Training> trainingList
String myVariable
}
json {
myVariable myVariable
trainings tmpl.training(trainingList ?: [])
}
,它的回应是:
{
"myVariable": null,
"trainings": [
{
"id": 3,
"name": "test t",
"numberOfAbsentClients": 0,
"startDate": "2016-11-20T09:00:00+0000",
"numberOfClients": 2,
"section": {
"id": 1,
"name": "test sec"
}
},
{
"id": 10,
"name": "test 2",
"numberOfAbsentClients": 0,
"startDate": "2016-11-09T11:00:00+0000",
"numberOfClients": 2,
"section": {
"id": 2,
"name": "sec 2"
}
}
]
}
推荐答案
好的,我找到了解决方法:
ok, I found solution:
render(view: "trainingsByClients", model: [trainingList: trainings, myVariable: "asdg"])
,所以我们应该使用render
而不是respond
.响应未正确添加其他模型对象.
so we should use render
instead of respond
. Respond is not adding properly additional model objects.
这篇关于在Gson中渲染少量模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文