I'm using Graisl 3.1.1, rest-api profile. I'm trying to build a Category Tree but I haven some problems rendering the categories in JSON-Views.
I'm using json templates, one for the parent and another for the child. Basically I want to generate a json for angular something like this:
These is my code.
Any help?
//domain
class Category {
ObjectId id /* MongoDB */
static hasMany = [categories: Category]
String name
...
//controller
def directory(){
def categories = Category.findAllByCategoriesIsNotNull([sort: 'name', order: 'asc'])
respond categories
}
//directory.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')
}
The problem is the categories
line above, I'm not sure what is the problem or my mistake.
//_child.gson
import com.example.Category
model {
Category child
}
json {
name child.name
}