我试图做一些事情,如果该值不存在,所以我可以更新它。但isExist函数总是返回undefined。我能用这个做什么?返回true实际返回undefined使用async
参考:Ero
已被定义。
async.forEachOf(idArray, function(value, key, cb) {
rp(baseURL + value)
.then(function(json) {
if (!isExist(json)) {
// do something
} else {
console.log(isExist(json), "It's not video or exists");
}
})
.catch(function(err) {
console.error(err);
})
cb();
}, function() {
res.status(200)
});
});
function isExist(data) {
let parsedData = JSON.parse(data);
if (parsedData.items[0].type === 'Video') {
Ero.find({
videoUri: parsedData.items[0].url_mp4
}, function(err, docs) {
if (docs.length) {
return true;
} else {
return false;
}
})
} else {
return false;
}
}
一个的jsfiddle将是很好 – Mazz