React native 反应本机Api和平面列表问题
我正在开发货币应用程序,我找到了api。 但是拉数据3次。我该怎么办? 顺便说一下,我不能在平板电脑上运行它。 也许这是api的问题,但也许我不明白。我的代码在这里React native 反应本机Api和平面列表问题,react-native,react-native-flatlist,React Native,React Native Flatlist,我正在开发货币应用程序,我找到了api。 但是拉数据3次。我该怎么办? 顺便说一下,我不能在平板电脑上运行它。 也许这是api的问题,但也许我不明白。我的代码在这里 export default class App extends Component { constructor(props) { super(props); this.state = { data: [], isLoading: true }; } component
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
data: [],
isLoading: true
};
}
componentDidMount() {
fetch('https://kur.doviz.com/api/v5/converterItems')
.then((response) => response.json())
.then((json) => {
this.setState({ data: json});
alert(this.state.data[1][3].text)
})
.catch((error) =>
{
alert(error)
})
.finally(() => {
this.setState({ isLoading: false });
});
}
render() {
const { data, isLoading } = this.state;
return (
<View style={{ flex: 1, padding: 24 }}>
{ isLoading ? <ActivityIndicator/> :
data.map((item , index) => {
return (
<View>
<Text>{data[0][1].text} - {data[0][1].buying} - {data[0][1].selling}</Text>
<Text>{data[0][2].text} - {data[0][2].buying} - {data[0][2].selling}</Text>
<Text>{data[1][1].text} - {data[1][1].buying} - {data[1][1].selling}</Text>
<Text>{data[1][2].text} - {data[1][2].buying} - {data[1][2].selling}</Text>
<Text>{data[1][3].text} - {data[1][3].buying} - {data[1][3].selling} </Text>
</View>
);
})
}
</View>
);
}
};
导出默认类应用程序扩展组件{
建造师(道具){
超级(道具);
此.state={
数据:[],
孤岛加载:正确
};
}
componentDidMount(){
取('https://kur.doviz.com/api/v5/converterItems')
.then((response)=>response.json())
。然后((json)=>{
this.setState({data:json});
警报(this.state.data[1][3].text)
})
.catch((错误)=>
{
警报(错误)
})
.最后(()=>{
this.setState({isLoading:false});
});
}
render(){
const{data,isLoading}=this.state;
返回(
{正在加载?:
data.map((项目、索引)=>{
返回(
{data[0][1]。text}-{data[0][1]。购买}-{data[0][1]。出售}
{data[0][2]。text}-{data[0][2]。购买}-{data[0][2]。销售}
{data[1][1]。text}-{data[1][1]。购买}-{data[1][1]。销售}
{data[1][2]。text}-{data[1][2]。购买}-{data[1][2]。销售}
{data[1][3]。text}-{data[1][3]。购买}-{data[1][3]。销售}
);
})
}
);
}
};