itemselector-multiselect的数据过滤

纠结了半天,重写不了方法,只好改源码了。
itemselector.js 源码:
    //从左到右的图片点击按钮时间,包括双击事件。
    fromTo : function() {
        var selectionsArray = this.fromMultiselect.view.getSelectedIndexes();
        var records = [];
        if (selectionsArray.length > 0) {
            for (var i=0; i<selectionsArray.length; i++) {
                record = this.fromMultiselect.view.store.getAt(selectionsArray[i]);
                records.push(record);
            }
            if(!this.allowDup)selectionsArray = [];
            for (var i=0; i<records.length; i++) {
                record = records[i];
                /**
                  *添加的代码
                  */
                for(var j=0; j<this.toMultiselect.view.store.getCount();j++){
                    var _toStoreRecord = this.toMultiselect.view.store.getAt(j);
                    if(record.get('列名')==_toStoreRecord.get('列名')){
                    //相同则不添加
                       return;
                    }
                }
                if(this.allowDup){
                    var x=new Ext.data.Record();
                    record.id=x.id;
                    delete x;
                    this.toMultiselect.view.store.add(record);
                }else{
                    this.fromMultiselect.view.store.remove(record);
                    this.toMultiselect.view.store.add(record);
                    selectionsArray.push((this.toMultiselect.view.store.getCount() - 1));
                }
            }
        }
        this.toMultiselect.view.refresh();
        this.fromMultiselect.view.refresh();
        var si = this.toMultiselect.store.sortInfo;
        if(si){
            this.toMultiselect.store.sort(si.field, si.direction);
        }
        this.toMultiselect.view.select(selectionsArray);
    },
   //从右到左的图片点击按钮时间,包括双击事件。

    toFrom : function() {
        var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
        var records = [];
        /**这里和上面差不多*/
        if (selectionsArray.length > 0) {
            for (var i=0; i<selectionsArray.length; i++) {
                record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
                records.push(record);
            }
            selectionsArray = [];
            for (var i=0; i<records.length; i++) {
                record = records[i];
                this.toMultiselect.view.store.remove(record);
                if(!this.allowDup){
                    this.fromMultiselect.view.store.add(record);
                    selectionsArray.push((this.fromMultiselect.view.store.getCount() - 1));
                }
            }
        }
        this.fromMultiselect.view.refresh();
        this.toMultiselect.view.refresh();
        var si = this.fromMultiselect.store.sortInfo;
        if (si){
            this.fromMultiselect.store.sort(si.field, si.direction);
        }
        this.fromMultiselect.view.select(selectionsArray);
    }

multiselect.js 源码(拖拽时的数据过滤):
源码中在继承Ext.dd.DropZone时有重写该方法,当拖拽的数据源对象在目标区域降落时会调用该函数。在里面改吧。
    // private
    onNodeDrop : function(n, dd, e, data){
        //略 当数据不符合时return false;才能取消拖拽
     }


改源码不太好,最好是自己重写组件。我是查了N久没查到能有帮助的资料,重写组件能力不行就只好改源码了。希望大虾提供更好的办法哈。

你可能感兴趣的:(ext)