【问题标题】:React-Native: Undefined is not an object although there is a decleration in frontReact-Native:尽管前面有声明,但未定义不是对象
【发布时间】:2016-11-26 04:09:10
【问题描述】:

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

未定义不是一个对象(评估'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();
    }

【问题讨论】:

    标签: javascript ios error-handling download react-native


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2021-08-06
      • 1970-01-01
      • 1970-01-01
      • 2022-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多