javascript - React-Native:虽然前面有声明,但 undefined 不是对象

标签 javascript ios error-handling download react-native

在下面的代码中,我下载了一个 JSON 文件。 之后我将它的字典数组传递给 downloadWebsiteData()。 在此函数中出现以下错误:

Undefined is not an object (evaluating 'web files.length')

这是我正在使用的代码:重要提示:webFiles 是一个数组!

downloadWebsiteData(webFiles) {


    this.setState({amountOfAllWebsites: webFiles.length});

    for(var ii = 0; ii < webFiles.length; ii++)
    {

      var urlToDownload = webFiles[ii].url;

      fetch(urlToDownload, {method: "GET"}).then((responseData) => {

          this.saveDataToLocalStorage(responseData, urlToDownload);
          alert('Save: '+urlToDownload);

          this.setState({actuallyLoadedWebsites: this.state.actuallyLoadedWebsites++});

          this.downloadWebsiteData();

      })
      .done();
    }

最佳答案

如果您查看上面代码中 fetch 方法中的这一行 this.downloadWebsiteData();。您没有将任何参数传递给函数 downloadWebsiteData()。如果您打算递归调用它,则需要将链接列表传递到那里的函数。

关于javascript - React-Native:虽然前面有声明,但 undefined 不是对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38523322/

相关文章:

javascript - 根据 Angular2 typescript 中的属性值分配类

javascript - 从 vuex 状态数组中创建计算属性数组以在 v-model 中使用

ios - 具有用户身份验证功能的 Facebook Like 按钮

javascript - 使用 arangodb 连接到多个数据库

javascript - 将 Bluebird Promisifyall 与 Mongoose 结合使用

python - InvalidArgumentError : tensorflow logits and labels still not broadcastable

javascript - 在 try block 中使用 try 来捕获不同的错误是一个好习惯吗? - JavaScript

python-3.x - 系统找不到指定的路径: error returned when changing field in admin page Django

ios - swift segue 未声明的类型破坏了代码

ios - 键盘出现时弹出 View 箭头移动