我可以在列表上拉取刷新,并且收到来自网络API的请求/响应(在日志中(,刷新状态更改,但列表中的值未更新,任何帮助将不胜感激。 我看不到刷新控件的任何错误,我相信我正在正确传递数据,有人可以帮助我吗?
constructor(props) {
super(props);
const dataSource = new ListView.DataSource({rowHasChanged: (row1, row2) => row1 !== row2});
this.state = {
dataSource: dataSource.cloneWithRows([]),
refreshing: false
};
this._renderRow = this._renderRow.bind(this);
this._getCoinData = this._getCoinData.bind(this);
}
componentWillMount() {
this._getCoinData();
}
_getCoinData() {
return new Promise((resolve) => {
getCryptocurrencyData()
.then(function (result) {
const ds = new ListView.DataSource({rowHasChanged: (row1, row2) => row1 !== row2});
this.setState({
dataSource: ds.cloneWithRows(result),
jsonData: result
});
resolve();
}.bind(this))
});
}
_renderRow(data) {
return (
<CoinCell coinName={data.name} coinPrice={data.price_gbp} coinPercentageChange={data.percent_change_24h}></CoinCell> )
}
_renderHeader() {
return (
<Header />
)
}
_onRefresh() {
this.setState({refreshing: true});
this._getCoinData()
.then(() => {
this.setState({refreshing: false});
});
}
render() {
return (
<View>
<ListView
enableEmptySections
refreshControl={
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this._onRefresh.bind(this)}
/>
}
ref={'resultListView'}
dataSource={this.state.dataSource}
renderRow={this._renderRow}
renderSeparator={(sectionId, rowId) => <View key={rowId} style={styles.separator}/>}
renderHeader={() => this._renderHeader()}
/>
</View>
);
}
解决方案:只要意识到我没有在获取调用中添加headers: {
'Cache-Control': 'no-cache, no-store'
}
。 使用的数据是缓存的数据。