渲染和响应自定义gson的不同(均为错误)输出 [英] Different (both bad) output for render and respond custom gson

查看:83
本文介绍了渲染和响应自定义gson的不同(均为错误)输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Grails 3.2.3,并在 grails-app / views / training 中创建了自己的视图: _short-training.gson

  import com.example.trainings.Training 

model {
训练训练
}

json g.render(训练,[includes:['id','name']])



short-index.gson

  import com.example.trainings.Training 

model {
Iterable< Training> trainingList
}

json tmpl.'short-training'(trainingList?:[])

$ b $控制器中的b

我尝试了两种不同的方法,但是其中没有一个正在工作。都返回200状态,而不是我收到的6个训练实例:

  render(view:short-index,model:[ trainingList:section.trainings])



 回复section.trainings,[status:OK,view:short-index] 

[]



训练在短指数.gson ,同时使用 render ,但不会进一步传递。 响应根本不通过培训。我缺少什么?

解决方案

替换

  json tmpl.'short-training'(trainingList?:[])

  json tmpl.'short-training'(training,trainingList?:[])

第一个参数可以用来指定模型变量名称

I'm using Grails 3.2.3 and created own views in grails-app/views/training:

in _short-training.gson

import com.example.trainings.Training

model {
    Training training
}

json g.render(training, [includes:['id', 'name']])

in short-index.gson

import com.example.trainings.Training

model {
    Iterable<Training> trainingList
}

json tmpl.'short-training'(trainingList ?: [])

in controller I tried two different approaches but noone of them is working. Both return 200 status but instead of 6 training instances I received:

    render(view: "short-index", model: [trainingList: section.trainings])

[null,null,null,null,null,null]

    respond section.trainings, [status: OK, view:"short-index"]

[]

it seems that trainings are visible in short-index.gson while used render but are not passed further. respond do not pass trainings at all. what am I missing?

解决方案

Replace

json tmpl.'short-training'(trainingList ?: [])

With

json tmpl.'short-training'("training", trainingList ?: []) 

The first argument can be used to specify the model variable name

这篇关于渲染和响应自定义gson的不同(均为错误)输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆