2016-07-22 43 views
0

在下面的代碼中,我已經下載了一個JSON文件。 然後我把它的一個字典數組傳遞給downloadWebsiteData()。 在這個函數中談到以下錯誤:React-Native:Undefined不是一個對象,雖然前面有一個decleration

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(); 
    } 

回答

1

如果你看一下這條線this.downloadWebsiteData();在上面的代碼中fetch方法中。您沒有將任何參數傳遞給函數downloadWebsiteData()。如果您打算遞歸調用它,則需要在那裏傳遞該函數的鏈接列表。

+0

謝謝!這只是我的一個愚蠢的錯誤。謝謝您的回答! –

相關問題