日期:2014-05-16  浏览次数:20301 次

EXTJS CheckboxGroup重写setValue与getValue方法
取到的值是:"1,2"这种形式

var wine = Ext.create('Ext.form.CheckboxGroup',{
            fieldLabel:'喜欢烟酒',
            labelAlign:'right',
            width:250,
            labelWidth:60,
            name:'smokes',
            items:[
                {anchor:'50%',boxLabel:'抽烟',name:'smoke',inputValue:'1'},
                {anchor:'50%',boxLabel:'喝酒',name:'wine',inputValue:'2'}
            ],
            getValue: function () {
                var val = [];
                this.items.each(function (c) {
                    if (c.getValue() == true)
                        val.push(c.inputValue);
                });
                return val.join(',');
            },
            setValue: function (val) {
                if (val.split) {
                    val = val.split(',');
                }
                this.reset();
                for (var i = 0; i < val.length; i++) {
                    this.items.each(function (c) {
                        if (c.inputValue == val[i]) {

                            c.setValue(true);
                        }
                    });
                }
            },
            reset: function () {
                this.items.each(function (c) {
                    c.setValue(false);
 &nb