Skip to content

Instantly share code, notes, and snippets.

@tleite
Last active December 15, 2015 06:49
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 tleite/5219073 to your computer and use it in GitHub Desktop.
Save tleite/5219073 to your computer and use it in GitHub Desktop.
This is a way to bind Bootstrap's accordion behavior directly in the view
<script>
ko.bindingHandlers.collapseAccordion = {
init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
if($(element).hasClass("collapse")){
$(element).removeClass("collapse").attr().addClass("in");
} else {
$(element).removeClass("in").addClass("collapse").attr("style","height:0px");
}
}
}
</script>
<div data-bind="collapseAccordion: conditionalStatement" class="accordion-body">
...
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment