extjs radioGroup怎么取值并显示画面上

var radiogroup= new Ext.form.RadioGroup({
                fieldLabel : "性别",
                items : [{
                            boxLabel : '男',
                            inputValue : '1',
                            checked : true,
                            name : "radSex"
                        }, {
                            boxLabel : '女,
                            name : "radSex",
                            inputValue : '2'
                        }]
    });

radiogroup.getValue()获取的是inputValue的值
radiogroup.setValue(“1”);//设置值选中


然后还需要重写radiogroup的两个方法,在按照我上面这样做就可以了
//RadioGroup重写的getValue和setValue
Ext.override(Ext.form.RadioGroup, {   
    getValue: function(){   
        var v;   
        if (this.rendered) {   
            this.items.each(function(item){   
                if (!item.getValue())    
                    return true;   
                v = item.getRawValue();   
                return false;   
            });   
        }   
        else {   
            for (var k in this.items) {   
                if (this.items[k].checked) {   
                    v = this.items[k].inputValue;   
                    break;   
                }   
            }   
        }   
        return v;   
    },   
    setValue: function(v){   
        if (this.rendered)    
            this.items.each(function(item){   
                item.setValue(item.getRawValue() == v);   
            });   
        else {   
            for (var k in this.items) {   
                this.items[k].checked = this.items[k].inputValue == v;   
            }   
        }   
    }   
});
posted @ 2012-04-15 23:31  helpwz  阅读(2626)  评论(0编辑  收藏  举报