zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
    @name Edo.controls.MultiCombo
    @class 
    @typeName MultiCombo
    @description 多选框下拉框
    @extend Edo.controls.Trigger
    @example 
*/
Edo.controls.MultiCombo = function(){
 
    Edo.controls.MultiCombo.superclass.constructor.call(this);
};
Edo.controls.MultiCombo.extend(Edo.controls.Trigger,{
    tableConfig: null,
    
    data: null,
    
    valueField: 'id',
    displayText: '名称',
    displayField: 'text',
    valueField: 'text',
    delimiter: ',',
        
    triggerPopup: true,
    readOnly: true,
    
    multiSelect: true,
//    _setValue: function(values){        
//        this.table.setValue(vs);
//    },
    setValue: function(vv){    
        this.table.setValue(vv);
    },
    getValue: function(){
    
        return this.table.getValue();
    },    
    
    viewText: function(){    
        var texts = [];
        
        var selecteds = this.table.getSelecteds();
        selecteds.each(function(o){
            texts.add(o[this.displayField]);
        }, this);
        this._setText(texts.join(this.delimiter));
    },
    
    _setData: function(data){
        if(typeof data === 'string') data = window[data];
        if(!data) return;
        if(!data.dataTable) data = new Edo.data.DataTable(data || []);
        
        this.data = data;
                
        if(this.table) this.table.set('data', data);
        
        this.changeProperty('data', data);        
    },
    
    onselectionchange: function(e){
        this.selectionchanged = true;
        this.viewText();
    },
    init: function(){    
        Edo.controls.MultiCombo.superclass.init.a(this, arguments);
        
        if(!this.table){
            this.table = Edo.create(Edo.apply({
                type: 'multiselect',
                style: 'border:0',
                width: '100%',
                height: '100%',
                autoHeight: true,
                multiSelect: this.multiSelect,
                minHeight: 80,
                maxHeight: 250,
                displayText: this.displayText,
                displayField: this.displayField,
                valueField: this.valueField,
                delimiter: this.delimiter,
                onselectionchange: this.onselectionchange.bind(this)
            }, this.tableConfig));
        }
        this.table.set('data', this.data);
    },
    showPopup: function(){    
        Edo.controls.MultiCombo.superclass.showPopup.a(this, arguments);
        
        if(!this.table.parent){
            this.popupCt.addChild(this.table);
        }
        var sels = this.table.getSelecteds().clone();
        this.table.set('data', this.data);
        this.table.selectRange(sels);
    },    
    hidePopup: function(){
        Edo.controls.MultiCombo.superclass.hidePopup.a(this, arguments);
        
        if(this.selectionchanged){
            this.fireEvent('selectionchange', {
                type: 'selectionchange',
                source: this
            });
        }
        this.selectionchanged = false;                
    }
});
 
Edo.controls.MultiCombo.regType('multicombo');