I, I know, there is a lot information about this on SO, but I didn't find the right answer for my situation.
I have this piece of code:
for(var i=0; i < shop.collections.length; i++){
if(!shop.collection[i].active){
var data = {
name: shop.collection[i].name,
visible: true
};
myOwnService.createCollection(data, accessToken, function(err, response, body){
shop.collections[i].serviceId = body.id;
})
}
My problem is that shop
is undefined in the myOwnService.createCollection()
service. What is the right way to access the shop
variable in the callback, so how I can update the object so I can save the result?