Skip to content

Instantly share code, notes, and snippets.

@bergquist
Created August 31, 2012 08:26
Show Gist options
  • Save bergquist/3550221 to your computer and use it in GitHub Desktop.
Save bergquist/3550221 to your computer and use it in GitHub Desktop.
backbone mixin
var MyBackboneView = Backbone.View.extend({
....
});
var FormMixin = {
prop: '',
getFormValue: function(name) {}
}
_.extend(MyBackboneView.prototype, FormMixin);
@eldewall
Copy link

Sätt mixin skit under ett namespace så man enklare kan följa i MyBackboneView att man anropar saker från mixin

var FormMixin = {
_base: {
fieldChanged: function (event) {
var element = $(event.currentTarget),
value = element.val(),
id = element.attr('id');

    if (element.is("[type='checkbox']")) {
        value = element.attr('checked') ? true : false;
    }

    this.model.set(id, value);
   }

}
}

MyBackboneView = Backbone.View.extend({

events: {
'change input' : '_base.fieldchanged'
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment