Created
February 25, 2011 21:55
-
-
Save andrewdeandrade/844569 to your computer and use it in GitHub Desktop.
updating model with nested collection attribute
This file contains 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
Project = Backbone.Model.extend({ | |
initialize: function() { | |
_.bindAll(this, 'getRules', 'saveRules'); | |
this.getRules(); | |
this.rules.bind('add', this.saveRules); | |
this.rules.bind('remove', this.saveRules); | |
}, | |
getRules: function() { | |
var rules = this.get("rules"); | |
this.rules = new RulesCollection(rules); | |
}, | |
saveRules: function() { | |
this.set({ "rules": this.rules }); | |
}, | |
save: function() { | |
this.collection.update(this); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment