我初步确定了状态,但发生了什么
已经导入了nessesary stuffs
import React, { Component } from 'react';
import { AppRegistry, FlatList, StyleSheet, ActivityIndicator ,ListView , Alert , Text, View } from 'react-native';
export default class FlatListBasics extends Component {
constructor(props) {
super(props);
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.states = {
isLoading : true ,
dataSource: {}
};
}
componentDidMount = () => {
fetch('https://jsonplaceholder.typicode.com/posts/1', {
method: 'GET' ,
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
Alert.alert("done");
this.setState({
data: responseJson ,
isLoading: false
}) })
.catch((error)=> { console.error(误差);
}); } render(){ 如果(!this.state.isLoading){ 回来( ); } 其他{ 回来( {item.body}} /> ); }
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 22
},
item: {
padding: 15,
borderBottomWidth: 2 ,
borderBottomColor: '#888888' ,
fontSize: 18,
height: 54,
},
})
我刚刚调用了this.state
答案 0 :(得分:0)
乍一看,您似乎已在构造函数中将this.state
拼写为this.states
...
...
this.states = {
isLoading : true ,
dataSource: {}
};...
将this.states
更改为this.state
:)