Skip to content

Instantly share code, notes, and snippets.

@theozaurus
Created November 2, 2011 23:01
Show Gist options
  • Save theozaurus/1335223 to your computer and use it in GitHub Desktop.
Save theozaurus/1335223 to your computer and use it in GitHub Desktop.
// Successful updating of a task
HTH.store.find(HTH.Project).get('firstObject').set('title','Updated the title!');
// Unsuccessful attempt to add a task to a project
var project = HTH.store.createRecord(HTH.Project, {title: "New" });
var task = HTH.store.createRecord(HTH.Task, {title: "New task" });
task.set('project',project);
project.get('tasks').pushObject(task);
// Models
HTH.Project = SC.Record.extend({
title: SC.Record.attr(String),
tasks: SC.Record.toMany('HTH.Task',{
inverse: 'project'
})
});
HTH.Task = SC.Record.extend({
title: SC.Record.attr(String),
project: SC.Record.toOne('HTH.Project', {
inverse: 'tasks'
})
});
HTH.Project.FIXTURES = [ { guid: 1, title: 'Send man to moon', tasks: [1,2]},
{ guid: 2, title: 'Master handstand', tasks: [3]}];
HTH.Task.FIXTURES = [ { guid: 1, title: 'Find rocket', project: 1},
{ guid: 2, title: 'Find fuel', project: 1},
{ guid: 3, title: 'Stand on hands', project: 2}];
HTH.store = SC.Store.create().from(SC.Record.fixtures);
// Controller
HTH.projectsController = SC.ArrayProxy.create({
content: HTH.store.find(HTH.Project)
});
<script type="text/x-handlebars">
{{#collection contentBinding="HTH.projectsController.content"}}
<h3>{{content.title}}</h3>
{{#collection contentBinding="content.tasks"}}
<span>{{content.title}}</span>
{{/collection}}
{{/collection}}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment