我正在尝试执行两个查找查询并将结果组合到一个数组中。
这是我的代码,它不起作用
if (req.query.materialNumber) {
MaterialStockItem.find({
componentN: req.query.materialNumber,
itemType: 'material'
}, function(err, docs) {
if (err)
throw err;
var matStock = docs;
StockItem.find({
componentN: req.query.materialNumber,
itemType: 'material'
}),
function(err, docs2) {
if (err)
throw err;
var stock = docs2
var combinedArray = matStock.concat(stock)
res.json(combinedArray)
}
})
}
答案 0 :(得分:0)
也许您可以使用forkJoin
示例
GetCursorPos(&cursorPos);
CComPtr<IUIAutomationElement> elFromPoint;
_automation->ElementFromPoint(cursorPos, &elFromPoint);
因此将代码更改为
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { forkJoin } from 'rxjs';
@Injectable()
export class DataService {
constructor(private http: HttpClient) { }
public requestDataFromMultipleSources(): Observable<any[]> {
let response1 = this.http.get(requestUrl1);
let response2 = this.http.get(requestUrl2);
let response3 = this.http.get(requestUrl3);
// Observable.forkJoin (RxJS 5) changes to just forkJoin() in RxJS 6
return forkJoin([response1, response2, response3]);
}
}