首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

EXTJS CheckboxGroup重写setValue与getValue步骤

2013-08-29 
EXTJS CheckboxGroup重写setValue与getValue方法取到的值是:1,2这种形式var wine Ext.create(Ext.for

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);
                });
            }

热点排行