I have simple knockout viewmodel:
function HumanViewModel(humanViewModel) {
if (humanViewModel=== undefined || humanViewModel=== null) {
humanViewModel= {};
}
var self = this;
var Id = humanViewModel.Id || '';
var Name = humanViewModel.Name || '';
}
I'm fetching some json data from a server, to fill this model, here is what's going on success:
var result = [];
for (var i = 0; i < receivedData.length; i++) {
var vm = new HumanViewModel({ Id: receivedData[i].Id, Name: receivedData[i].Name });
result.push(vm);
}
self.Humans.push.apply(self.Humans, result);
The problem is here: var vm = new HumanViewModel({ Id: receivedData[i].Id, Name: receivedData[i].Name });. Variable vm contains HumanViewModel, but this viewmodel doesn't contain Id and Name, it simply contains nothing;
However, when I'm looking at debugger, inside HumanViewModel everything works fine, but in the end, vm contains nothing.
I have no idea, where data have been lost. How can I solve this problem?