【发布时间】:2016-01-03 02:02:54
【问题描述】:
这可能是一个明显的答案,但我不确定采取什么方法。 请求是一个节点模块:https://github.com/request/request 我填充了一组 getHistory 请求(使用不同的参数)。 p = [p1,p2...]。
this.app.all('/api/heatmap', function(req,res) {
// fill p here _.each(blabla, p.push(gethistory(someparams...)
var result = [];
function getHistory(params) {
var options = { ...};
var callback = function(error, response, body) {
if(error) { //wtv
} else {
// what to do with the body here ? return body ? result.push(body) ?
}
}
request(options, callback);
}
Q.all(p).then(function() {
});
}
所以这里的问题是我在完成所有请求时,将所有内容放在一个数组/对象中,然后将整个内容发送给客户端。如何让 getHistory 返回获取的值(请求完成后)。
希望清楚。
【问题讨论】: