// Example data...
var data = [
{
id: 1,
parent_name: 'root category 1',
children: [
{
id: 11,
child_name: 'sub category 1a'
},
{
id: 12,
child_name: 'sub category 1b'
}
]
},
{
id: 2,
parent_name: 'root category 2',
children: [] // some root categories have no child-nodes.
}
];
var directive = {
'li': {
'category<-': {
'li': {
'subcategory<-category.children': {
'.': 'subcategory.child_name'
}
},
'.': function(a) {
if (this.children.length) {
// Prepend the parent name before the already rendered children.
return this.parent_name + a.CURRENT_VALUE;
} else {
// Discard the non-populated children OL tags from the nested list.
return this.parent_name;
}
}
}
}
};
$('div').render(data,directive);
var directive = {
'li': {
'category<-': {
'li': {
'subcategory<-category.children': {
'.': 'subcategory.child_name'
}
},
'+.': 'category.parent_name'
}
}
};
var directive = {
'li': {
'category<-': {
'li': {
'subcategory<-category.children': {
'.': 'subcategory.child_name'
}
},
'+.': function(a) {
// This would actually be a clean solution if anyone knows how!
if (!this.children.length) a.prepend = false;
return this.parent_name;
}
}
}
};
'ol@style': function(a){
return this.children.length ? '' : 'display:none';
}
var directive = {
'li': {
'category<-': {
'ol': {
'subcategories<-category.has_children': {
'li': {
'subcategory<-category.children': {
'.': 'subcategory.child_name'
}
},
},
},'+.': 'category.parent_name'
}
}
};