apefify不要在地图功能中推动项目

发布于 2025-01-25 03:27:26 字数 781 浏览 2 评论 0 原文

我有这个函数,该功能带有_.map函数,该功能循环每个元素或数组
一个比它可以在apefify存储中推出的项目,但数据集的元素永远是0。
为什么?

const Apify = require('apify')
const _ = require('underscore');

Apify.main(async () => {
    let item = {}
    let array = []

    const dataset = await Apify.openDataset('dataset2', {forceCloud: true});

    await mapping([1, 2, 3, 4, 5]);


    function mapping(array){
        _.map(array, async function (el) {
            console.log("====")
            console.log(el)
            console.log("====")
            await dataset.pushData(item) // <---- no items pushed
        })
    }
});

这是屏幕:

I have this function that call a new one with _.map function that cycle each element or array
an than it could push items in Apify Storage, but the element of dataset is ever 0.
Why?

const Apify = require('apify')
const _ = require('underscore');

Apify.main(async () => {
    let item = {}
    let array = []

    const dataset = await Apify.openDataset('dataset2', {forceCloud: true});

    await mapping([1, 2, 3, 4, 5]);


    function mapping(array){
        _.map(array, async function (el) {
            console.log("====")
            console.log(el)
            console.log("====")
            await dataset.pushData(item) // <---- no items pushed
        })
    }
});

this is the screen:
apify storage

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你又不是我 2025-02-01 03:27:26

正常地图功能不支持异步/等待。要么积聚成一个新数组,然后将其推入或用于(...的const ... of ...)循环

The normal map function doesn't support async/await. Either accumulate into a new array and push that or use for (const ... of ...) loop

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文