Skip to content

Instantly share code, notes, and snippets.

@HenrikJoreteg
Created November 6, 2010 15:53
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 HenrikJoreteg/665499 to your computer and use it in GitHub Desktop.
Save HenrikJoreteg/665499 to your computer and use it in GitHub Desktop.
Demonstrating the point of my recent pull request to backbone: https://github.com/documentcloud/backbone/pull/59
var View = Backbone.View.extend({
initialize: function () {
this.handleBindings();
},
contentBindings: {
title: '.title'
},
classBindings: {
selected: '.title',
color: '.someClass'
}
});
var View = Backbone.View.extend({
initialize: function () {
_.bindAll(this, 'changeTitle', 'changeSelected', 'changeColor');
this.model.bind('change:title', this.changeTitle);
this.model.bind('change:selected', this.changeSelected);
this.model.bind('change:color', this.changeColor);
},
changeTitle: function () {
this.$('.title').text(this.model.get('title'));
},
changeSelected: function () {
if (this.model.get('selected')) {
this.$('.title').addClass('active');
} else {
this.$('.title').removeClass('active');
}
},
changeColor: function () {
this.$('.someClass').removeClasss(this.model.previous('color')).addClass(this.model.get('color'));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment