Take a look at this example.
I've tried to simplify it as much as possible, but I'm still struggling to figure out where I went wrong.
Any help would be greatly appreciated ))
P.S Stack Overflow requires code, not just a link to jsfiddle. Here is the code snippet:
html:
<form action="" method="GET" data-bind="FacebookContacts">
<table class="importContacts table import">
<thead>
<tr>
<td></td>
<td>Photo</td>
<td>Name</td>
<td>Login</td>
</tr>
</thead>
<tbody data-bind="foreach: contacts">
<tr>
<td>
<span data-bind="text:FullName"></span>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</form>
Javascript:
var FacebookContactsViewModel = function () {
var _self = this;
_self.FacebookContacts = ko.observable();
_self.GetData = function() {
var localData=ko.mapping.fromJS(JSON.parse(contacts));
_self.FacebookContacts(localData);
ko.applyBindings(_self);
};
_self.GetData();
};
var contacts='{"contacts":[{"FullName":"Petr Perelygin"}]}';
var vm = new FacebookContactsViewModel();