我有一个像这样的javascript数组: [[1,2,3], [4,5,6]]
1,2,3和4,5和6是我的关注者ID在完成查找操作之后。我想将输出发送到浏览器。
有人可以让我知道如何显示结果或将结果发送到浏览器吗?
for(var i = 0; i<idName.length; i++ ) {
tempJson = {user_id: followerId, feed_content_text: finalFeedText };
notifications.push(tempJson);
var conditions = {
user_id: followerId,
external_id: key
};
FeedModel.findOne(conditions, function (err, data) {
//What condition should i write to send the output to browser when, it is done for all 'idNames'
res.send({
success: true,
message: finalMsgs
});
});
}
您是否尝试过以下方法:
var result = [];// initialize result array
for(var i = 0; i<idName.length; i++ ) {
tempJson = {user_id: followerId, feed_content_text: finalFeedText };
notifications.push(tempJson);
var conditions = {
user_id: followerId,
external_id: key
};
FeedModel.findOne(conditions, function (err, data) {
result.push(data);//storing data in result
if((i+1) === idName.length) { // check if all is completed
res.send({ // sending response
success: true,
message: finalMsgs,
data: result
});
}
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句