2015-06-20 71 views
2

我正在嘗試使用原生的簡單應用程序。我想從一個頁面下載一個json數組並將其顯示爲一個listview。 我這樣做React原生提取不是函數

var listApp = React.createClass({ 

fetchData : function() { 
    fetch(requestURL) 
    .then((response) => response.json()) 
    .then((responseData) => { 
     console.log(responseData); 
    }) 
    .done(); 
}, 
componentDidMount: function() { 
    this.fetchData(); 
    this.setState({ 
    dataSource: this.state.dataSource.cloneWithRows(elements) 
    }); 
}, 

但這樣做我從Chrome中調試程序出現錯誤fetch is not a function。我以這種方式取回var fetch = require("fetch");

回答

5

你不需要require它。這是一個瀏覽器版本的polyfill,與瀏覽器版本一樣,它始終可用於全局範圍。

+0

未找到頁面,「電影示例」,請更新您的答案。 – Aveek