Skip to content

Instantly share code, notes, and snippets.

@dmy3k
Created March 29, 2018 07:57
Show Gist options
  • Save dmy3k/0ac4506b427a5b4a0ab3d57e0cf632b1 to your computer and use it in GitHub Desktop.
Save dmy3k/0ac4506b427a5b4a0ab3d57e0cf632b1 to your computer and use it in GitHub Desktop.
/**
* Renders part of the view instead all of it.
* Useful in sutuations where view contains counter and input fields.
* Counter needs to be updated, while input state left intact.
* */
Backbone.View.prototype.renderPartial = function(selector, data, template) {
template = template || this.template;
var self = this;
var $html = $('<div>' + template(data) + '</div>');
selector.split(',').forEach(function(q) {
q = q.trim();
self.$(q).replaceWith($html.find(q));
});
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment