Skip to content

Instantly share code, notes, and snippets.

@frekw
Created September 18, 2010 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frekw/a159097b0df22d7dde9f to your computer and use it in GitHub Desktop.
Save frekw/a159097b0df22d7dde9f to your computer and use it in GitHub Desktop.
sc_require('models/project');
MyApp.Project.FIXTURES = [
{
guid:1,
name: "Foo"
},
{
guid:2,
name:"Bar"
}
];
MyApp.main = function main(){
var projects = MyApp.store.find(MyApp.Project);
MyApp.projectsController.set('content', projects);
}
MyApp.projectsController = SC.ArrayController.create({});
MyApp.mainPage = SC.Page.design({
// snip..
mainPane: SC.MainPane.design({
childViews: [SourceListView.design({
contentValueKey: "name",
contentBinding: "MyApp.sourcesController.arrangedObjects",
selectionBinding: "MyApp.sourcesController.selection"
})]
})
// snip..
})
MyApp.Project = SC.Record.extend({
name: SC.Record.attr(String)
})
sc_require('controllers/projects.js')
MyApp.sourcesController = SC.TreeController.create({
content: null,
projects:'',
projectsBinding: 'MyApp.projectsController.content',
buildSources: function(){
var p = this.get('projects'),
projectsSource;
if(!p) return;
projectsSource = this.buildProjectsSource(p);
console.log(projectsSource);
var sources = SC.Object.create({
treeItemIsExpanded: YES,
treeItemChildren: [SC.Object.create({
treeItemIsExpanded: YES,
group: true,
name: "Projects",
treeItemChildren: projectsSource
})]
});
this.set('content', sources); // watch the console explode as this causes an inifnite loop.
}.observes('projects'),
buildProjectsSource: function(projects){
var ret = [];
for(var i = 0, len = projects.length(); i < len; i++)
ret.push(SC.Object.create({
name: projects.objectAt(i).get('name')
}));
return ret;
}
}) ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment