当前位置:编程学习 > JS >>

Extjs2.2 RadioGroup的声明对象和getValue、SetValue方法的用法

用过的朋友都知道extjs的RadioGroup组件的setValue和SetValue貌似有bug。是不成功的

在此我来解决一下这个问题:

1、声明RadioGroup的代码:


[javascript] 
var radiogroup= new Ext.form.RadioGroup({ 
                fieldLabel : "性别", 
                items : [{ 
                            boxLabel : '男', 
                            inputValue : '1', 
                            checked : true, 
                            name : "radSex" 
                        }, { 
                            boxLabel : '女, 
                            name : "radSex", 
                            inputValue : '2' 
                        }] 
    }); 
2、重写SetValue和GetValue两个方法从而得到可用的方法

[javascript] 
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;    
            }    
        }    
    }    
}); 
3、调用方法完成设置:

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

补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,