Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save erichocean/144822 to your computer and use it in GitHub Desktop.
Save erichocean/144822 to your computer and use it in GitHub Desktop.
App.adviceListController = SC.ArrayController.create({
sourceRoot: function() {
var groups = {}, headings = [], group, adviceAry, ret ;
var source = this.get('content') ;
if (!source) return null ;
source.forEach(function(advice) {
if (group = advice.get('group')) {
adviceAry = groups[group] ;
if (!adviceAry) groups[group] = adviceAry = [] ;
adviceAry.push(group);
if (headings.indexOf(group) < 0) headings.push(group) ;
}
}, source);
// once divided into kinds, create group nodes for each kind
ret = [];
headings.forEach(function(group) {
adviceAry = groups[group];
ret.push(SC.Object.create({
displayName: "%@".fmt(group).loc(),
isExpanded: YES,
children: adviceAry
}));
});
return SC.Object.create({ children: ret, isExpanded: YES });
}.property('[]').cacheable()
});
App.adviceTreeController = SC.TreeController.create({
contentBinding: 'App.adviceListController.sourceRoot',
allowsEmptySelection : NO,
allowsMultipleSelection : NO,
treeItemChildrenKey: 'children',
treeItemIsExpandedKey: 'isExpanded',
treeItemIsGrouped: YES
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment