【发布时间】:2019-05-22 12:12:39
【问题描述】:
我有 React Native 项目,当我尝试构建我的手机时,我收到了这个错误消息。 警告:数组或迭代器中的每个子元素都应该有一个唯一的“key”属性。但它适用于计算机模拟器。
这里是json数据:http://hazir.net/api/match/today
这是我的代码,
import React from 'react';
import { FlatList, ActivityIndicator, Text, View } from 'react-native';
export default class Matches extends React.Component {
constructor(props){
super(props);
this.state ={ isLoading: true}
}
componentDidMount(){
return fetch('http://hazir.net/api/match/today')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
dataSource: responseJson,
}, function(){
});
})
.catch((error) =>{
console.error(error);
});
}
render(){
if(this.state.isLoading){
return(
<View style={{flex: 1, padding: 20}}>
<ActivityIndicator/>
</View>
)
}
return(
<View style={{flex: 1, paddingTop:20}}>
<FlatList
data={this.state.dataSource}
renderItem={({item}) => <Text>{item.matchId}, {item.matchDate}</Text>}
keyExtractor={({id}, index) => id}
/>
</View>
);
}
}
【问题讨论】:
标签: json reactjs react-native networking