Created
May 14, 2012 02:32
-
-
Save amccloud/2691450 to your computer and use it in GitHub Desktop.
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
var categoryClassTransformer = function(value) { | |
return (value) ? value.toLowerCase().replace(/ /g, '') : ''; | |
}; | |
var triedClassTransformer = function(value) { | |
return (value == true) ? 'tried' : 'todo'; | |
}; | |
var Meal = Backbone.Model.extend({}), | |
MealLogView = Backbone.View.extend({ | |
tagName: 'form', | |
className: 'meal-log', | |
template: _.template($('#meal-log').html()), | |
bindings: { | |
'class': ['category', categoryClassTransformer], | |
'class': ['tried', triedClassTransformer], | |
'text h1.name': 'name', | |
'value input[name="name"]': 'name', | |
'value textarea[name="notes"]': 'notes', | |
'checked input[name="tried"]': 'tried' | |
}, | |
events: { | |
'submit': 'save' | |
}, | |
save: function(event) { | |
alert("Save: " + JSON.stringify(this.model.toJSON())); | |
return false; | |
}, | |
render: function() { | |
this.$el.html(this.template()); | |
return this.bindModel(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment