Grails将json呈现给特定的视图 [英] Grails rendering json to specific view
本文介绍了Grails将json呈现给特定的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
def create(){
render(view:/ book / create,model:[bookInstance:new Book(params)])
}
我如何渲染到上面的特定视图,而是返回json?我已经尝试了以下几项:
def create(){
def bookInstance = new Book(params )
render(view:/ book / create,model:[bookInstance as JSON]);
}
我已经导入了所需的JSON库。
谢谢。
解决方案
模型期待地图。如果没有钥匙,你不能只放任何东西。您的第一个示例具有以下设置:
render(view:/ book / create,model:[bookInstance:bookInstance as JSON ])
in a controller I am trying to render json to a specific view. Here is what I was doing before using json :
def create() {
render(view: "/book/create", model: [bookInstance: new Book(params)])
}
How would I render to a specific view like above but return json instead ? I have tried a few things like the following :
def create() {
def bookInstance = new Book(params)
render(view:"/book/create", model: [bookInstance as JSON] );
}
I have imported the required JSON library.
Thanks.
解决方案
The model is expecting a map. You can't just put anything in there without a key. Your first example has the setup:
render(view: "/book/create", model: [bookInstance: bookInstance as JSON])
这篇关于Grails将json呈现给特定的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文