[Sencha ExtJs6 Modern] 多选list在清空store之后,list.getSelections()居然还能得到原来选的records

原文链接:http://blog.youkuaiyun.com/lovelyelfpop/article/details/52102619



一个配置了mode: 'MULTI'的list,就支持了多选操作。

为方便演示,请看这个示例:https://fiddle.sencha.com/#fiddle/1eka


操作步骤:

1、在list中选择几条记录(record),比如选择3条

2、点击"getSelectionCount"按钮,得到的值为3


3、点击"onRemoveAll"按钮,清空list


4、再点击"getSelectionCount"按钮,得到的值还是为3,而不是0




原因分析:

onSelectionStoreRemove: function(store, records) {    
    var me = this,
        selected = me.selected,
        ln = records.length,
        removed, record, i;
    if (me.getDisableSelection()) {
        return;
    }
    for (i = 0; i < ln; i++) {
        record = records[i];
        if (selected.remove(record)) {
            if (me.getLastSelected() == record) {
                me.setLastSelected(null);
            }
            if (me.getLastFocused() == record) {
                me.setLastFocused(null);
            }
            removed = removed || [];
            removed.push(record);
        }
    }
    if (removed) {
        me.fireSelectionChange([
            removed
        ]);
    }
},
onSelectionStoreClear: function(store) {
    var records = store.getData().items; 
    this.onSelectionStoreRemove(store, records); //这里的'records' 应该是被移除的那些records, 而不是store中剩下的records
}

上面是'Ext.mixin.Selectable'类里的一部分代码,'Ext.mixin.Selectable' 是一个mixin,dataview和list用到了这个mixin。

在调用store.removeAll() 之后,会执行上面的 'onSelectionStoreClear' 函数,然后里面又调用了 'onSelectionStoreRemove' 函数。

'onSelectionStoreRemove' 函数的第二个参数应该是被移除的records,而 'onSelectionStoreClear' 传给它的确是store中剩下的records(removeAll之后,当然是空数组)。

解决办法:

写一个override,因为 'Ext.mixin.Selectable' 是mixin,override它是没用的,你应该override用到这个mixin的其它类,比如dataview。

Ext.define('Ext.overrides.dataview.DataView', {    
    override: 'Ext.dataview.DataView',

    onSelectionStoreClear: function(store, records) {
        this.onSelectionStoreRemove(store, records); //这里的'records' 应该是被移除的那些records, 而不是store中剩下的records
    }
});






欢迎加入Sencha Touch + Phonegap交流群

1群:194182999 (满)

2群:419834979

共同学习交流(博主QQ:479858761


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

神秘_博士

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值