0
我正在使用lodash库进行迭代。为此,我使用了_.map()函数。我有一个问题,我在_.map()中有一个异步函数。我的代码是这样的:在_.map()中使用异步函数
let dataToRender = {};
let modifiedData = _.map(myArray, (element) => {
dataToRender.uuid = element.UID;
dataToRender.pendingAmountReceived = element.$.SR;
dataToRender.orderID = element.TransactionID;
dataToRender.orderAmount = element.TransactionValue;
dataToRender.orderDate = moment(element.TransactionTime, 'YYYY-MM-DDTHH:mm:ss');
dataToRender.goal = element.Product.replace('amp;', '&');
dataToRender.currentStatus = 'waiting';
//Here CheckFilter is my asynchrounous function
//I have to do calculation base on the response of this checkFilter
checkFilter(requireParams)
.then(data => {
//If the response returned from checkFilter is false I have to include this data
if (!data) {
return requireParams;
}
});
});
res.json(modifiedData);
但我刚刚null在modifiedData中。如何获取所有数据?
唉,这就是我的一天 –