Skip to content

Instantly share code, notes, and snippets.

@mstum
Created May 20, 2011 19:54
Show Gist options
  • Save mstum/983658 to your computer and use it in GitHub Desktop.
Save mstum/983658 to your computer and use it in GitHub Desktop.
Switching between multiple Views?
<script type="text/javascript">
var viewModel = {
currentView: ko.observable("template-1")
};
viewModel.template = ko.dependentObservable(function(){
return this.currentView();
}, viewModel);
$(document).ready(function() {
ko.applyBindings(viewModel);
});
</script>
</head>
<body>
<h1>Template:</h1>
<div id="templateContent" data-bind='template: { name: template() }'></div>
<h2>Toggle</h2>
<input type="button" value="One" onclick="javascript:viewModel.currentView('template-1');" />
<input type="button" value="Two" onclick="javascript:viewModel.currentView('template-2');" />
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment