I can display value of serviceId to console but when I try to compare it in if(), I got this error. Can you tell me why does this happend and how to solve it, please?
var servicesCompare1 = [];
var servicesCompare2 = [];
$.getJSON("http://localhost:55972/api/status", function (data) {
self.services(data.services);
self.lastCheck = data.lastCheck;
servicesCompare1 = (data.services);
});
function DashboardRefresh() {
self.servicesRefresh = ko.observable([]);
$.getJSON("http://localhost:55972/api/status", function (data) {
servicesCompare2 = (data.services);
self.servicesRefresh(data.services);
});
if (servicesCompare2.length > servicesCompare1.length) {
for (i = 0; i < (servicesCompare2.length-1); i++) {
console.log(servicesCompare2[i].serviceId);
if (servicesCompare1[i].serviceId !== servicesCompare2[i].serviceId) {
self.services.push(servicesCompare2[i]);
}
}
}
}
setInterval(DashboardRefresh, 5000);
Console output: 47 48 49 ... other Ids
Uncaught TypeError: Cannot read property 'serviceId' of undefined at DashboardRefresh (NetworkStatus.html:66)
Aucun commentaire:
Enregistrer un commentaire