我得到了一个任务,要把下面的mongoose查询中的数组传递给一个回调函数,但作为一个初学者,我不知道如何正确地做这件事。
meme.find({}, (err, meme) => {
const memes = meme.map(m => m);
// Use the array, pass it to a service, or pass to a callback
});const memes = meme.map(m => m);是问题中的数组。
请问,谁能解释一下我如何将它传递给回调函数?
谢谢。
发布于 2018-06-27 19:15:35
您可以将其包装在匿名函数中并传递该数组。然后在您想要的任何地方使用该数组
(function (memes){
meme.find({}, (err, meme) => {
// You can access memes array here
});
}(memes));https://stackoverflow.com/questions/51061175
复制相似问题