-
-
Save theozaurus/1335223 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
// 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); |
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
// 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) | |
}); |
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
<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