映射功能未分配对象的值[nodjes]

时间:2018-08-01 16:22:52

标签: node.js array.prototype.map

有人可以告诉我为什么未给返回的对象分配值吗? 有了libary的那一刻,我想将datestamp格式化为四分之一值,以便可以在前端很好地显示它。这是处理来自前端的请求并通过Express发送回去的控制器。

  exports.getHistoricalOpp = async (req, res) => {
  const hisOpps = await Opportunity.find({original_id: req.params.id, deleted_opportunity: true});
  const modHisOpps = hisOpps.map(async (el) => {
    const formatQuarter = await moment(el.timing).format("Q");
    el.quarter = formatQuarter;
    console.log(el.timing);
    return el;
  });
  await Promise.all(modHisOpps).then(data => {
    console.log('response',data);
    res.json(data);
  }).catch(err => {
    console.log(err)
  })
}

响应:

[ { _id: 5b61bc933d93fc2dc0a3d11a,
[]     account_name: 'Fieten Olie',
[]     name: 'PriceCast',
[]     amount: 5000,
[]     timing: 2018-09-30T00:00:00.000Z,
[]     scotsman: 63,
[]     weighted_amount: 3150,
[]     status: 'afspraak gepland',
[]     order_received: false,
[]     deleted_opportunity: true,
[]     sales_rep: 5b47a9af4977815d4c7a0bc2,
[]     created_on: 2018-08-01T13:58:43.523Z,
[]     original_id: 5b61bc933d93fc2dc0a3d11a,
[]     __v: 0 },
[]   { _id: 5b61bca03d93fc2dc0a3d11b,
[]     account_name: 'Fieten Olie',
[]     name: 'PriceCast',
[]     amount: 4000,
[]     timing: 2018-09-30T00:00:00.000Z,
[]     scotsman: 63,
[]     weighted_amount: 2520,
[]     status: 'afspraak gepland',
[]     order_received: false,
[]     original_id: 5b61bc933d93fc2dc0a3d11a,
[]     deleted_opportunity: true,
[]     sales_rep: 5b47a9af4977815d4c7a0bc2,
[]     created_on: 2018-08-01T13:58:56.289Z,
[]     __v: 0 },
[]   { _id: 5b61bca83d93fc2dc0a3d11c,
[]     account_name: 'Fieten Olie',
[]     name: 'PriceCast',
[]     amount: 4000,
[]     timing: 2018-09-30T00:00:00.000Z,
[]     scotsman: 75,
[]     weighted_amount: 3000,
[]     status: 'afspraak gepland',
[]     order_received: false,
[]     original_id: 5b61bc933d93fc2dc0a3d11a,
[]     deleted_opportunity: true,
[]     sales_rep: 5b47a9af4977815d4c7a0bc2,
[]     created_on: 2018-08-01T13:59:04.810Z,
[]     __v: 0 } ]

扩展后的结果是:element.quarter = 3。

0 个答案:

没有答案