Created
July 24, 2011 19:01
-
-
Save mxriverlynn/1102944 to your computer and use it in GitHub Desktop.
model binding example for backbone
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
| AddEditView = Backbone.View.extend({ | |
| events: { | |
| "change input": "fieldChanged", | |
| "change select": "selectionChanged", | |
| }, | |
| selectionChanged: function(e){ | |
| var field = $(e.currentTarget); | |
| var value = $("option:selected", field).val(); | |
| var data = {}; | |
| data[field.attr('id')] = value; | |
| this.model.set(data); | |
| }, | |
| fieldChanged: function(e){ | |
| var field = $(e.currentTarget); | |
| var data = {}; | |
| data[field.attr('id')] = field.val(); | |
| this.model.set(data); | |
| }, | |
| render: function(){ | |
| // various jquery template things, here | |
| } | |
| }); |
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
| AddEditView = Backbone.View.extend({ | |
| render: function(){ | |
| // various jquery template things, here | |
| Backbone.ModelBinding.call(this); | |
| } | |
| }); |
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
| AddEditView = Backbone.View.extend({ | |
| formBindings: { | |
| "change #someInput": "modelAttribute" | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment