Skip to content

Instantly share code, notes, and snippets.

@andrewburgess
Created May 21, 2013 17:48
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 andrewburgess/5621777 to your computer and use it in GitHub Desktop.
Save andrewburgess/5621777 to your computer and use it in GitHub Desktop.
KnockoutJS binding that clears out the initial element before applying the template. Allows for server side generation of a repeatable element, that can then be rebound with Knockout
ko.bindingHandlers.templateWithClear = {
init: function (element, valueAccessor) {
element.innerHTML = '';
return ko.bindingHandlers.template.init(element, valueAccessor);
},
update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
return ko.bindingHandlers.template.update(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment