读书人

ExtJs中FormPanel中碰到radiogroup、c

发布时间: 2012-11-10 10:48:50 作者: rapoo

ExtJs中FormPanel中遇到radiogroup、checkboxgroup值!!!

在Extjs中常常会遇到各种各样的问题,诸如在FormPanel中出现radiogroup、checkboxgroup与数据库交互时的提交时,你需要的是字符串格式或者指定的格式,但提交时显示的(如:json格式)仍然是一个数组形式,不如我们重写(override)它的getValue()来转换成我们的格式如何?那么我们这样实现:

?

因为各人遇到的情况不同,而解决的办法就更加不同,重写了checkboxgroup的getValue我发现仍然解决不了我的问题,因为我发现即使我重写了getValue()方法,它依然返回的是个数组,但又确定调用了我重写的getValue()方法,郁闷了半天,都不知道问题出在哪里?

??????? 重新整理思路:我左边是个扩展了GridPanel的Grid,右边是扩展了FormPanel的Form,要求在Grid中选中一行时,右边的FormPanel就可以加载该数据,在这个过程中,加载数据到checkboxgroup中需要重写(override)才能加载:

Ext.override(Ext.form.CheckboxGroup,{        setValueForItem : function(val){            val = String(val).split(',');        this.items.each(function(item){                item.setValue(false);   //初始化,所有的checkbox未定。        });        //this.items.each()<====>this.eachItem();                this.items.each(function(item){            if(val.indexOf(item.inputValue)> -1){   //中提取,面上checkbox的inputValue比判是否中。                item.setValue(true);    //可理解以下:            }                     /*              等于:             for(var i=0;i<val.length;i++){                 if(var[i]==item.inputValue){                     item.setValue(true);                 }             }                */        });       }});Ext.override(Ext.form.BasicForm,{   findField : function(id){   //此部份是了BasicForm能找到不只是FormField,他能用于radiogroup、checkboxgroup的情.        var field = this.items.get(id);             if(!field){            this.items.each(function(f){                if((f.isXType('radiogroup')||f.isXType('checkboxgroup'))&& (f.dataIndex == id || f.id == id || f.getName() == id)){                    field = f;                    return false;                }                                      if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){                    field = f;                    return false;                }            });        }        return field || null;    }    ,updateRecord : function(record){ //既然已能用于radiogroup、checkboxgroup了!那在Form中然就要其置取的值啦!        record.beginEdit();        var fs = record.fields;        fs.each(function(f){            var field = this.findField(f.name);            if(field){                var value = field.getValue();                                if ( value.getGroupValue ) {                    value = value.getGroupValue();                                   } else if ( field.eachItem ) {         var re = "";          field.eachItem(function(item){             if(item.getValue() == true){                   re += item.inputValue + ",";               }          });if (re.length > 0){value = re.substr(0,re.length - 1);  }else{value = re}                }                record.set(f.name, value);            }        }, this);        record.endEdit();        return this;    }});
?

?

?

?

读书人网 >JavaScript

热点推荐