receiving an empty array, outside of an function ?
var triggerImageQuery = function(start, length,callback) {
var feedData = [];
var feedInfo = result.rows[start];
var imgQuery = pgFormat("select * from feedImages where feedId=%L",feedInfo.feedid);
model.client.query(imgQuery,function(err,result){
if(result.rows.length > 0){
var imgArr =[];
for(var j=0;j<result.rows.length;j++){
var image = "http://"+config.host+":"+config.port+"/"+result.rows[j].imageurl;
imgArr.push(image);
}
feedData.push(feedInfo);
feedData.push(imgArr);
}
else{
feedData.push(feedInfo);
}
console.log(feedData) // prints data correctly
});
console.log(feedData) // here data gets empty?
if(start < length) {
start++;
triggerImageQuery(start, length-1);
}
callback(feedData); // unable to callback here because of empty array`
}
triggerImageQuery(0, result.rows.length,function(result){
res.json(result); // `result is empty`
});
even i have tried with declaring the var feedData = []; at the top, but no use.
and also tried the callback inside the model.client.query but there is an error like TypeError: callback is not an function.