2017-06-15 28 views
0

我有一个域类:如何在不定义内部模板的情况下使用Grails JSON视图?

class Business { 
    String name 
    String description 
} 

我有以下的JSON模板:

index.gson:生成JSON的对象

列表

_business.gson:生成JSON的业务对象

index.gson

import server.Business 
model { 
    Iterable businessList 
} 
json { 
    result tmpl.business(businessList ?: []) 
} 

_business.gson

model { 
     Business business 
} 
json { 
    id business.id 
    name business.name 
} 

怎样才能JSON的业务对象,而无需使用_business.gson模板吗?

我想去一个方法,我只是有index.gson并手动渲染内部对象。

import server.Business 
model { 
    Iterable businessList 
} 

json { 
    **WHAT SHOULD I ADD HERE?** 
} 

json(businessList.toList()) { 
    **I also noticed that I can use this syntax, BUT WHAT SHOULD I ADD HERE?** 
} 

回答

1

你可以在json闭包内做任何你想做的事情。

json(businessList.toList()) { Business business -> 
    id business.id 
    name business.name 
    description business.description 
} 
相关问题