Here is example.
I simplified it as much as i could, but i still can’t understand where i’m wrong.
Please help me ))
P.S stackoverflow require a code, not just link to jsfiddle, so this is it:
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();
Take a look at here and make your code more simpler and easier to read:
http://jsfiddle.net/NpK3K/24/
The problem was that you are putting an object into the
"FacebookContacts"property and not an Array. So you should use the"with"binding extension at the first place for root element to change the datacontext for nested elements.Hope it helps.