0
我试图重新在文档中使用https://facebook.github.io/react-native/docs/network.html打印从取()的结果做出反应
componentDidMount: function(){
this.createRow();
},
createRow : function(){
var results = fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
return responseJson.movies;
});
this.setState({
'xyz' : results,
'people' : [{'name':'something_else', 'email':'[email protected]'}, {'name':'morgan', 'email':'[email protected]'}]
});
},
不过的例子,当我转到在render
方法打印结果
render: function(){
console.log(this.state.xyz)
我得到: undefined
第一次页面呈现(和xyz
尚未设置,这样才有意义)
Promise { <state>: "pending" }
为什么我收到pending
状态,而不是movies
对象,如示例显示了当呈现页面时,第二次(createRow()
从componentDidMount
运行)?
ahhh right ok!谢谢 –