javascript - 如何在 mongoose 中将此数组传递给回调 'meme.find({}, (err, meme) => { const memes = meme.map(m => m); });'
问题描述
我得到了将以下猫鼬查询中的数组传递给回调的任务,但是作为初学者,我不知道如何正确执行此操作。
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);
是问题中的数组。
拜托,有人可以阐明我如何将它传递给回调吗?
谢谢。
解决方案
您可以将其包装在匿名函数中并传递该数组。然后在任何你想要的地方使用那个数组
(function (memes){
meme.find({}, (err, meme) => {
// You can access memes array here
});
}(memes));
推荐阅读
- reactjs - 如何在 Amplify Datastore 中创建动态查询
- jupyter-notebook - 在 Jupyter Notebook 幻灯片放映期间隐藏代码周围的蓝色框
- azure-ad-b2c - 在 B2C 自定义策略中复制 dateTime 声明
- php - 在自定义主题中发布“特色图片”显示错误
- python - 带有包含 ColumnTransformer 的管道的 RFECV
- javascript - 在 Jest/RTL 中模拟单个变量
- pine-script - 如果收盘价 >= sma 线,则仅在第一根蜡烛上绘制形状?其他蜡烛没有绘制形状,即使它们的收盘也 >= sma
- linux - 有人可以帮我处理这些 shell 脚本行吗?我无法理解这些行中的 DEBUG 有什么用
- flutter - 数据不会在颤振中返回到未来的构建中
- .htaccess - 在特定情况下强制使用斜线 htaccess