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

ExtJs中FormPanel中碰到radiogroup、checkboxgroup時賦值問題!

2012-11-10 
ExtJs中FormPanel中遇到radiogroup、checkboxgroup時賦值問題!!!在Extjs中常常会遇到各种各样的问题,诸如在

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

?

?

?

热点排行