Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 16, 2014 17:29
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/ef6c8849d5c5011645cd to your computer and use it in GitHub Desktop.
Save devdays/ef6c8849d5c5011645cd to your computer and use it in GitHub Desktop.
Object JavaScript - Observable Array Bound to a Table
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Bind Observable Array to Table</title>
</head>
<body>
<table border="0">
<thead>
<tr>
<th>Product</th>
<th>Type</th>
</tr>
</thead>
<tbody data-bind="foreach: productArray">
<tr>
<td data-bind="text: product"></td>
<td data-bind="text: type"></td>
</tr>
</tbody>
</table>
<script src="Scripts/knockout-2.2.1.debug.js"></script>
<script>
var productArray = ko.observableArray([
{ product: "Widget", type: "Tool" },
{ product: "Bolt", type: "Fastener" },
{ product: "Washer", type: "Fastener" },
{ product: "Screwdriver", type: "Tool" }
]);
ko.applyBindings(new productArray());
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment