【发布时间】:2016-03-26 19:56:36
【问题描述】:
我正在使用 async.parallel 来处理数据,然后我会将收集到的数据传递给我的视图。
但是在函数中,我得到了 JSON,但我不能使用它的字段。
async.parallel(jsearch, function(err, results) {
console.log(results);
console.log(results[0]);
res.render('t.ejs', {
user : req.user,
board : collected,
images : results
});
});
console.log(results) 返回 JSON
[ [ { _id: 565779c91dd21c0014d2bb21,
created_on: Thu Nov 26 2015 21:29:45 GMT+0000 (GMT),
like_count: 1,
path: 'uploads/73fb95126e626af139c094c167753d9b',
author: '246519777',
__v: 0,
likers: [] } ],
[ { _id: 565b818b3f5aa8740334967d,
created_on: Sun Nov 29 2015 22:51:55 GMT+0000 (GMT),
like_count: 36,
path: 'uploads/27ef8a8ec19929c6000d47e3943710da',
author: '246519777',
__v: 0,
likers: [] } ],
[ { _id: 565b818b3f5aa8740334967d,
created_on: Sun Nov 29 2015 22:51:55 GMT+0000 (GMT),
like_count: 36,
path: 'uploads/27ef8a8ec19929c6000d47e3943710da',
author: '246519777',
__v: 0,
likers: [] } ] ]
console.log(results[0]) 返回该 json 中的第一项
[ { _id: 565779c91dd21c0014d2bb21,
created_on: Thu Nov 26 2015 21:29:45 GMT+0000 (GMT),
like_count: 1,
path: 'uploads/73fb95126e626af139c094c167753d9b',
author: '246519777',
__v: 0,
likers: [] } ]
console.log(results[0].path) 返回未定义。
为什么?
【问题讨论】:
标签: json node.js asynchronous