Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 16, 2014 20:30
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 devdays/522f90fda3432ed78076 to your computer and use it in GitHub Desktop.
Save devdays/522f90fda3432ed78076 to your computer and use it in GitHub Desktop.
Object JavaScript - Knockout with Inline template
<!DOCTYPE html>
<html>
<head>
<title>Binding List to Template</title>
</head>
<body>
<h2>Products</h2>
<table data-bind="template: { name: 'producttemplate', foreach: productArray }">
</table>
<script type="text/html" id="producttemplate">
<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>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment