Created
November 29, 2012 12:14
-
-
Save vangberg/4168596 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="jquery-1.8.3.js"></script> | |
<script src="jquery.tmpl.min.js"></script> | |
<script src="knockout-2.2.0.js"></script> | |
</head> | |
<body> | |
<input data-bind='value: users()[0].name' /> | |
<h2>Good</h2> | |
<div data-bind='template: {name: "good-template", foreach: users}'></div> | |
<h2>Bad</h2> | |
<div data-bind='template: {name: "bad-template", foreach: users}'></div> | |
<script id="good-template" type="text/x-jquery-tmpl"> | |
<div> | |
${name()} | |
</div> | |
</script> | |
<script id="bad-template" type="text/x-jquery-tmpl"> | |
<div data-bind='click: function() {}'> | |
${name()} | |
</div> | |
</script> | |
<script type="text/javascript"> | |
var user = {name: ko.observable()}; | |
var viewModel = {users: ko.observableArray()}; | |
viewModel.users.push(user); | |
ko.applyBindings(viewModel); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jquery.tmpl variables in a template doesn't get updated if it is inside an HTML element with a
data-bind
.