Created
December 16, 2014 17:29
-
-
Save devdays/ef6c8849d5c5011645cd to your computer and use it in GitHub Desktop.
Object JavaScript - Observable Array Bound to a Table
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
<!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