React native Listview 使用react-redux时候更新不起效果

解决了一个React Native项目中ListView无法刷新的问题,通过调整数组操作方式从使用unshift改为concat实现数据更新并触发视图刷新。

这个项目开发一个月了,接近尾声,前几天遇到一个问题,正如题目所说,我检查了所有的代码逻辑,没有发现任何问题,但是就是不给我刷新,删除也不刷新,我就日了够了,我就不信了。我决定重新去看下文档。

当我看到:

http://reactnative.cn/docs/0.31/listviewdatasource.html

这个文档的

我们使用concat方法来修改this._data以创建新数组,注意不能使用push方法拼接数组

的时候,抱着怀疑的态度去修改一下。

我了个大曹

修改前的代码:

// 入口函数,需要先存储历史数据,然后再进行展示

export function createHistoryData(rowData) {
    return (dispatch) => {
        let dao = new NetInfoDataDAO();

        historyList.unshift(rowData);
        dao.save(historyList).then((msg) => {
            dispatch(historyDataSuccess(historyList));
            Toast.show('测试成功', { position: px2dp(-80) });
        }, (msg) => {
            historyList.shift();  //save failed, pop the data from the list
            Toast.show('测试失败', { position: px2dp(-80) });
        });
    };
}

修改后的代码:

// 入口函数,需要先存储历史数据,然后再进行展示

export function createHistoryData(rowData) {
    return (dispatch) => {
        let dao = new NetInfoDataDAO();
        historyList = [rowData].concat(historyList)
        // historyList.unshift(rowData);
        dao.save(historyList).then((msg) => {
            dispatch(historyDataSuccess(historyList));
            Toast.show('测试成功', { position: px2dp(-80) });
        }, (msg) => {
            historyList.shift();  //save failed, pop the data from the list
            Toast.show('测试失败', { position: px2dp(-80) });
        });
    };
}

哎呀。坑啊。是我不了解原理。为啥要用两个不同的数组。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值