【发布时间】:2020-03-16 01:21:50
【问题描述】:
我想从 React Native 的 RSS 中获取按发布日期排序的数据
我使用了这个代码:
fetch('url here')
.then((response) => response.text())
.then((responseData) => rssParser.parse(responseData))
.then((rss) => {
this.setState({
description : rss.items,
isLoading : true
});
rss.items.map((value, index) => {
this.setState({
dateStack : this.state.description[index].published
});
});
});
在这里,dateStack 是数据排序日期的数组 但它没有得到排序的数据,只得到一个数据...... 谁能帮我? 请告诉我该怎么做~
【问题讨论】:
-
setState是异步的,因此您不能在 map 方法中依赖this.state。
标签: javascript reactjs react-native rss fetch