javascript - How to reuse render function for multiple views in Backbone? -
i'm working on app in backbone, , have multiple views have same render function:
render: function(){ this.$el.html(this.template(this.model.tojson())); return this; }
how reuse function in multiple views can follow old dry way?
you can use mixin pattern specified here: proper way of doing view mixins in backbone
var renderable = { render: function(){ this.$el.html(this.template(this.model.tojson())); return this; } }; var view = backbone.view.extend({ //other methods }); _.extend(view.prototype, renderable); var myview = new view(); myview.render();
Comments
Post a Comment