4
In my code I consulted 2 services and placed their results (objects) inside an array called deferreds
.
These objects have a property called results
, which is another array
.
I need to take the first of these objects, and give one push()
of all the results
of the other objects in it, for I will display it in a popup
.
My problem is that it only works when I put one breakpoint
in the browser and go line by line. When I run normal in the browser, it gives an error saying that def.results[0]
is undefined, but when I go slow debugando
it does have a value, and everything turns normal.
Any hint?
var deferred = null;
deferreds.forEach(function (def) {
if (deferred == null) {
deferred = def;
} else {
def.results[0].forEach(function (defer) {
deferred.results[0].push(defer);
});
}
});
this.mapa.infoWindow.setFeatures([deferred]);
this.mapa.infoWindow.show(evt.mapPoint);
making def.Results[0]. foreach you are not traversing the array, you are only accessing the value, which alone cannot be traversed. removes this [0] ai that will work :D from a console.log() ae and takes the object
– Gabriel Rodrigues
What gives
console.log(JSON.stringify(deferreds));
? You can enter the code of the two services you consult?– Sergio
I think you’re trying to access the results before the deferred has been resolved.
– bfavaretto
Thanks @Gabrielrodrigues, is that inside the Results there was an array. The first position with the objects I mentioned, and another empty. That’s why I put [0].
– Wellington Fernandes
Thanks @bfavaretto. I’m not sure but I think the problem was that. I managed to solve using the
when
of the DOJO Framework I’m using, to access the property of eachresults
– Wellington Fernandes
Thanks @Sergio, I think the problem was that the deferred was not ready at all. Already put as I solved
– Wellington Fernandes