论坛首页 Web前端技术论坛

RadioGroup和CheckboxGroup的赋值问题

浏览 21417 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-10-07  

在Ext2.2的Ext.form.FormPanel中如果有RadioGroup或者CheckboxGroup,那么FormPanel.form.setValues方法对这2个东东内部的radio和checkbox无法动态赋值,需要对Ext.form.BasicForm的findField方法进行修正,代码如下:

Ext.override(Ext.form.BasicForm,{
    findField : function(id){        
        var field = this.items.get(id);        
        if(!field){
            this.items.each(function(f){
                if(f.isXType('radiogroup')||f.isXType('checkboxgroup')){
                    f.items.each(function(c){
                        if(c.isFormField && (c.dataIndex == id || c.id == id || c.getName() == id)){
                            field = c;
                            return false;
                        }
                    });
                }
                                
                if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
                    field = f;
                    return false;
                }
            });
        }
        return field || null;
    } 
});

 

   发表时间:2008-10-12  
这段代码要放在那里呀?
0 请登录后投票
   发表时间:2008-10-13  
随便哪里都可以,它只是重写了Ext.form.BasicForm的findField方法。
0 请登录后投票
   发表时间:2008-11-25  
请问如何在动态的添加checkgroup的items,或者从服务器读取列表生成
0 请登录后投票
   发表时间:2008-11-26   最后修改:2008-11-26
我的jsp页面返回值如下:
{data:[{name:'jk',lrb:['104','106','103','300','301','100','102']}]}
但在js中setValue还是不能对checkboxgroup赋值.而textfiled是可以的.
js代码:
   store = new Ext.data.JsonStore({
	  url:'getrolemod.jsp?roleid='+rid,
      //id: 'id',
     //totalProperty: 'total',
      root: 'data',
      fields: ['name','lrb'],
	  remoteSort: false
	});	
  	
	  	Ext.QuickTips.init();
	  	simple = new Ext.FormPanel({
			labelWidth:60,
			//baseCls: 'x-plain',
			autoHeight:true,
			url:"role_mod.jsp",
			frame:true,
			defaultType:'textfield',
			bodyStyle:'padding:2px 2px 0',
			items:[
			    {
			     fieldLabel: '角色名',
			     name:'name',
			     maxLength:20,
			     maxLengthText:'角色不能超过20个字',
			     blankText:'不能为空',
			     readOnly:true,
			     allowBlank:false,
			     anchor:'100%'
			     },{
			        xtype:'fieldset',
	                title: '权限设置',
	                autoHeight: true,
	                defaultType: 'checkbox', 
	                //layout: 'form',
	                items: [
	                {
			     	    xtype: 'checkboxgroup',
	                    fieldLabel: '外协录入',
	                    columns: 2,
	                    items: [
	                        {boxLabel: '外协申请批件', name: 'lrb' ,inputValue:'100'},
	                        {boxLabel: '合同洽谈', name: 'lrb ',inputValue:'101'},
	                        {boxLabel: '市场准入材料', name: 'lrb',inputValue:'102'},
	                        {boxLabel: '网上审批', name: 'lrb' ,inputValue:'103'},
	                        {boxLabel: '合同信息', name: 'lrb' ,inputValue:'104'},
	                        {boxLabel: '付款情况', name: 'lrb' ,inputValue:'105'},
	                        {boxLabel: '检查验收', name: 'lrb' ,inputValue:'106'}
	                        ]
	                    },{
	                    xtype: 'checkboxgroup',
	                    fieldLabel: '查询',
	                    itemCls: 'x-check-group-alt',
	                    columns: 2,
	                    items: [
	                        {boxLabel: '科研生产计划', name: 'lrb',inputValue:'201'},
	                        {boxLabel: '综合查询', name: 'lrb',inputValue:'202'},
	                        {boxLabel: '成果查询', name: 'lrb',inputValue:'203'},
	                        {boxLabel: '报表查询', name: 'lrb',inputValue:'204'}
	                        //{boxLabel: '合同信息', name: 'cb-auto-5'}
	                        ]
	                    },{
	                    xtype: 'checkboxgroup',
	                    fieldLabel: '高级设置',
	                    columns: 2,
	                    items: [
	                        {boxLabel: '本科室项目', name: 'lrb',checked: true,inputValue:'300'},
	                        {boxLabel: '本人负责项目', name: 'lrb', checked: true,inputValue:'301'},
	                        {boxLabel: '研究内容', name: 'lrb',inputValue:'302'},
	                        {boxLabel: '开题报告', name: 'lrb',inputValue:'303'}
	                        //{boxLabel: '合同信息', name: 'cb-auto-5'}
	                        ]
	                    }
	                ]
			     }
			]
			});

     store.on('load',function(){
	       form1.setValues(store.getAt(0).data);
       });
       store.load(); 

0 请登录后投票
   发表时间:2008-12-09  
up一下!
请楼主解答一下如何赋值的问题.
0 请登录后投票
   发表时间:2008-12-09   最后修改:2008-12-09
非常不幸,checkboxgroup并不能批量赋值,你必须这样:

var form = new Ext.FormPanel({
    items:[{
        xtype: 'checkboxgroup',   
        fieldLabel: '外协录入',
        columns: 3,
        items: [   
          {boxLabel: '外协申请批件', name: 'lrb1' ,inputValue:'100'},   
          {boxLabel: '合同洽谈', name: 'lrb2',inputValue:'101'},   
          {boxLabel: '市场准入材料', name: 'lrb3',inputValue:'102'},   
          {boxLabel: '网上审批', name: 'lrb4' ,inputValue:'103'},   
          {boxLabel: '合同信息', name: 'lrb5' ,inputValue:'104'},   
          {boxLabel: '付款情况', name: 'lrb6' ,inputValue:'105'},   
          {boxLabel: '检查验收', name: 'lrb7' ,inputValue:'106'}   
          ]
    }]
});
form.form.setValues({lrb1:true,lrb2:true,lrb4:true,lrb5:true,lrb7:true});

0 请登录后投票
   发表时间:2008-12-24  
无意中看到这个帖子。呵呵。谢谢啦解决啦我的问题哈。
0 请登录后投票
   发表时间:2008-12-31  
请教下楼主,为什么我运行以下代码没赋值,

microboat 写道
非常不幸,checkboxgroup并不能批量赋值,你必须这样:

var form = new Ext.FormPanel({
    items:[{
        xtype: 'checkboxgroup',   
        fieldLabel: '外协录入',
        columns: 3,
        items: [   
          {boxLabel: '外协申请批件', name: 'lrb1' ,inputValue:'100'},   
          {boxLabel: '合同洽谈', name: 'lrb2',inputValue:'101'},   
          {boxLabel: '市场准入材料', name: 'lrb3',inputValue:'102'},   
          {boxLabel: '网上审批', name: 'lrb4' ,inputValue:'103'},   
          {boxLabel: '合同信息', name: 'lrb5' ,inputValue:'104'},   
          {boxLabel: '付款情况', name: 'lrb6' ,inputValue:'105'},   
          {boxLabel: '检查验收', name: 'lrb7' ,inputValue:'106'}   
          ]
    }]
});
form.form.setValues({lrb1:true,lrb2:true,lrb4:true,lrb5:true,lrb7:true});


  • 大小: 5.3 KB
0 请登录后投票
   发表时间:2008-12-31  
应该是js代码吧
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics