Created
July 10, 2009 21:16
-
-
Save erichocean/144822 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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