我正在使用 Graisl 3.1.1,rest-api 配置文件。我正在尝试构建类别树,但在 JSON 视图中呈现类别时遇到了一些问题。
我正在使用 json 模板,一个用于父级,另一个用于子级。基本上我想为这样的角度生成一个json:
这是我的代码。
有什么帮助吗?
//领域
class Category {
ObjectId id /* MongoDB */
static hasMany = [categories: Category]
String name
...
//控制器
def directory(){
def categories = Category.findAllByCategoriesIsNotNull([sort: 'name', order: 'asc'])
respond categories
}
//目录.gson
import com.example.Category
model {
Iterable<Category> categoryList
}
json {
categories g.render(template: 'parent', collection: categoryList ?: [], var: 'category')
}
//_parent.gson
import com.example.Category
model {
Category category
}
json {
id category.id.toString()
name category.name
categories g.render(template: "category/child", collection: category.categories ?: [], var: 'child')
}
问题是categories
上面的行,我不确定是什么问题或我的错误。
//_child.gson
import com.example.Category
model {
Category child
}
json {
name child.name
}