Ext 编辑FormPanel时,根据带入的值选中CheckBoxGroup

问题描述:
Ext 2.2中的CheckBoxGroup组件有点问题,FormPanel加载的数据无法选中CheckBox

解决方法:
1、给CheckboxGroup打一个补丁

Ext.override(Ext.form.CheckboxGroup, {
			getNames : function() {
				var n = [];

				this.items.each(function(item) {
							if (item.getValue()) {
								n.push(item.getName());
							}
						});

				return n;
			},

			getValues : function() {
				var v = [];

				this.items.each(function(item) {
							if (item.getValue()) {
								v.push(item.getRawValue());
							}
						});

				return v;
			},

			setValues : function(v) {
				// var r = new RegExp('(' + v.join('|') + ')');
				
				this.items.each(function(item) {
							var rawVal = item.getRawValue();
							if (v.contains(rawVal)) {//Contains为自定义扩展
								item.setValue(true);
							}else{
								item.setValue(false);
							}
						});
			}
		});


2、在FormPanel加载数据完成后,调用CheckboxGroup的setValues(arr)方法,设置checkbox的选中状态,代码如下:
index.adWin.doLoadLocalForm(record);
				//手动设置CheckBox的值
				if(record.get('ctrolArea')==0){//不控制地区
					Ext.getCmp('ctrolAreaGroupCmp').setValues([0]);
				}else{
					Ext.getCmp('ctrolAreaGroupCmp').setValues(record.get('adArea'));
				}
				if(record.get('ctrolSiteType')==0){//不控制网站类型
					Ext.getCmp('ctrolSiteTypeGroupCmp').setValues([0]);
				}else{
					Ext.getCmp('ctrolSiteTypeGroupCmp').setValues(record.get('adSiteType'));
				}


参考:[url]http://www.extjs.com/forum/showthread.php?t=39161 [/url]

你可能感兴趣的:(PHP,ext)