Skip to content

Instantly share code, notes, and snippets.

@amccloud
Created May 14, 2012 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amccloud/2691450 to your computer and use it in GitHub Desktop.
Save amccloud/2691450 to your computer and use it in GitHub Desktop.
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