Skip to content

Instantly share code, notes, and snippets.

@tristanz
Created October 22, 2010 06:52
Show Gist options
  • Save tristanz/640071 to your computer and use it in GitHub Desktop.
Save tristanz/640071 to your computer and use it in GitHub Desktop.
Problem binding functions with variables within a template.
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://nje.github.com/jquery-tmpl/jquery.tmpl.js"></script>
<script src="http://github.com/downloads/SteveSanderson/knockout/knockout-1.1.0.js"></script>
</head>
<body>
<div data-bind="template: 'myTemplate'"></div>
<script id="myTemplate" type="text/html" >
<a href="#" data-bind="click: function () { alert(${ i }) }">Alert</p>
</script>
<script>
$(document).ready(function() {
viewModel = {
i : ko.observable(47),
};
ko.applyBindings(viewModel);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment