Created
December 16, 2014 19:08
-
-
Save devdays/d9070350edc5bc5ee143 to your computer and use it in GitHub Desktop.
Object JavaScript - Named Template Example
This file contains 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
<body> | |
<h2>Products</h2> | |
<table data-bind="template: { name: 'product-template', foreach: productArray }"> | |
</table> | |
<script type="text/html" id="product-template"> | |
<tr> | |
<td data-bind="text: product"></td> | |
<td data-bind="text: type"></td> | |
</tr> | |
</script> | |
<script src="Scripts/knockout-2.2.1.debug.js"></script> | |
<script type="text/javascript"> | |
function ViewModel() { | |
this.productArray = ko.observableArray([ | |
{ product: "Widget", type: "Tool" }, | |
{ product: "Bolt", type: "Fastener" }, | |
{ product: "Washer", type: "Fastener" }, | |
{ product: "Screwdriver", type: "Tool" } | |
]); | |
} | |
ko.applyBindings(new ViewModel()); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment