I am currently working with a JSON array that I have read in. My goal is to convert each object within the array into a Knockout (KO) observable so that it can be properly mapped to the function.
function Person(data)
{
this.name = ko.observable(data.name);
this.age = ko.observable(data.age);
this.link = ko.observable(data.link);
}
function ViewModel()
{
var self = this;
self.Persons = ko.observableArray([]);
var JSONdataFromServer;
$.getJSON('http://127.0.0.1:8080', function(data) {
self.Persons(data);
for(var k in self.Persons) {
k = $.map(k, function(item) { return new Person(item) });
}
});
}
However, when running this code snippet (only a portion of it), an error occurs stating "Cannot use 'in' operator to search for '0' in G". My main objective remains converting the JSON objects within the Persons array into KO observable objects of type Person.