调用RefreshControl后,ListView数据不会更新

问题描述 投票:0回答:1

我可以在列表上刷新并且接收来自网络API的请求/响应(在日志中),刷新状态改变但是列表中的值不更新,任何帮助都将被理解。我可以看到RefreshControl没有错误,我相信我正确传递数据,任何人都可以帮助我吗?

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>
    );
}
reactjs listview react-native mobile
1个回答
0
投票

解决方案:刚刚意识到我没有在fetch调用中添加headers: { 'Cache-Control': 'no-cache, no-store' }。使用的数据是缓存的数据。

© www.soinside.com 2019 - 2024. All rights reserved.