如何在nodejs回调数组中向对象添加属性?

时间:2016-07-19 01:11:09

标签: javascript node.js

exports.index = function(req, res) {
  console.log('collec req', req.query.queryObject)
  Collection.all(req.user._id, function(err, collections) {
    if (!err) {
      console.log('collections', collections);
      Vote.find( {user: req.user._id}, function(err, votes) {
        if (!err) {
          for (var i = 0; i < votes.length; i++) {
            for (var j = 0; j < collections.length; j++) {
              console.log('collection match')
              if (collections[j]['whiskey'] == votes[i]['whiskey']) {
                collections[j]['voteId'] = votes[i]['_id'];
                collections[j]['userVote'] = votes[i]['vote'];
              }
            }
          }
          res.send(collections);
        }
      });
    };
  },
  req.query);
};

对于上述函数,console.log指示何时存在匹配,但userVote未添加到匹配的集合中。

0 个答案:

没有答案