0
我想用SectionList
來反應原生。從多個網址獲取和存儲SectionList的部分數據的數據
export default class Home extends React.Component {
constructor(props) {
super(props);
this.state = {
dataSource: [
{
title: 'New List', data: []
},
{
title: 'Old list', data: []
},
]
}
}
render() {
return (
<SectionList
style={styles.SectionContainer}
sections={this.state.dataSource}
renderSectionHeader={this._renderSectionHeader}
renderItem={this._renderItem}
keyExtractor={(item) => item.id}
/>
)
}
}
每個部分的數據可以通過不同的網址中獲取,而他們基本上具有相同的JSON數據:
getNewList() {
const url = website + '/api/new-list/';
return fetch(url)
.then((res) => res.json())
.catch((err) => console.log(err))
},
getOldList() {
const url = website + '/api/old-list/';
return fetch(url)
.then((res) => res.json())
.catch((err) => console.log(err))
}
如何獲取並存儲既爲SectionList
的dataSource
響應數據?
是的,使用axios使它好多了。謝謝。 – Aamu