`
microboat
  • 浏览: 59379 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

RadioGroup和CheckboxGroup的赋值问题

阅读更多

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

 

分享到:
评论
13 楼 八岭书生 2013-07-30  
请问下  {lrb1:true,lrb2:true,lrb4:true,lrb5:true,lrb7:true} 这个要如何动态拼装?
12 楼 hejin1026 2009-02-10  
一个很简单的问题,只需要form。load()的回调方法加入 对checkgroup这个field的对应值解析(一般是,分割值)在对该field的checkbox setValue()即可

这样的话,不需要对chekcbox赋不一样的name,还有就是楼主的方法 其实还是需要对该field的返回值 进行解析的
11 楼 microboat 2009-01-14  
必须加入顶楼的Ext.override代码。
10 楼 hany 2009-01-07  
同问,如何动态的添加checkgroup的items。没提供add方法啊
9 楼 boscohxy 2008-12-31  
应该是js代码吧
8 楼 boscohxy 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});


7 楼 379548695 2008-12-24  
无意中看到这个帖子。呵呵。谢谢啦解决啦我的问题哈。
6 楼 microboat 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});

5 楼 sunrise2008 2008-12-09  
up一下!
请楼主解答一下如何赋值的问题.
4 楼 ibet 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(); 

3 楼 ibet 2008-11-25  
请问如何在动态的添加checkgroup的items,或者从服务器读取列表生成
2 楼 microboat 2008-10-13  
随便哪里都可以,它只是重写了Ext.form.BasicForm的findField方法。
1 楼 vuens 2008-10-12  
这段代码要放在那里呀?

相关推荐

    界面控件之选项组件(RadioGroup和CheckBox)--代码

    本教程将重点讨论两种常用的选项组件:RadioGroup和CheckBox。它们都是用于提供多选或单选功能,但使用方式有所不同。 RadioGroup是一个可以容纳多个RadioButton的容器,通常用于实现单选功能。在一个RadioGroup中...

    Radiogroup、Checkbox、Toast

    标题中的“Radiogroup、Checkbox、Toast”是Android开发中常用的三个组件,它们在构建用户界面时起着关键作用。让我们深入探讨这三个组件及其在Android应用开发中的使用。 Radiogroup 是一个布局容器,用于管理一...

    android mars视频代码 Activity Activity_07源码 RadioGroup RadioButton CheckBox

    RadioGroup RadioButton CheckBox www.mars-droid.com/Android开发视频教程 代码 源码 mars老师讲课 android 视频源码 Activity_07(在此特别感谢mars的无私奉献,此代码为跟随视频边学边做的)

    ext checkboxgroup 回填数据解决

    重写 代码如下: //解决checkboxgroup回填数据问题 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 和 ViewPager 联动

    RadioGroup 和 ViewPager 联动

    RadioGroup和Fragment

    在实际项目中,我们可能还会遇到如何在Fragment中处理点击事件,如何在Fragment和Activity之间传递数据,以及如何处理Fragment的保存和恢复状态等问题。掌握RadioGroup和Fragment的用法,对于提升Android应用的用户...

    ListView项中包含RadioGroup解决混乱选中的问题

    然而,在ListView的每一项(Item)中嵌套RadioGroup和RadioButton时,可能会遇到一个常见的问题:当用户滑动ListView时,RadioButtons的选择状态可能会出现混乱,即之前被选中的RadioButton不再保持选中状态。...

    应用源码之RadioAndCheckbox.zip

    在Android开发中,RadioGroup和CheckBox是两种常用的控件,它们在用户界面中扮演着重要的角色,用于实现单选和多选功能。本资源“应用源码之RadioAndCheckbox.zip”提供了一组关于RadioGroup和CheckBox的源码示例,...

    RadioGroup和RadioButton实现FragmentTabHost导航效果

    在Android开发中,`RadioGroup`和`RadioButton`是一对常用的组件,它们通常用于实现单选功能,即在多个选项中只能选择一个。在本例中,我们将它们应用于`FragmentTabHost`的导航效果,创建一个可以切换不同`Fragment...

    RadioGroup自定义选项卡样式

    public void onCheckedChanged(RadioGroup group, int checkedId) { for (int i = 0; i < group.getChildCount(); i++) { RadioButton button = (RadioButton) group.getChildAt(i); if (button.getId() == ...

    RadioGroup

    RadioGroup和RadioButton是Android开发中常用的UI组件,用于实现单选功能。在移动应用设计中,当用户需要从多个选项中选择一个时,通常会用到这种控件。本示例将详细介绍RadioGroup和RadioButton的基本使用方法、...

    RadioGroup+fragment实现切换

    RadioGroup和Fragment是Android开发中的两个重要组件,它们在构建用户界面时发挥着关键作用。RadioGroup主要用于创建单选按钮组,让用户只能选择一个选项,而Fragment则用于创建可动态添加、移除或替换的模块化屏幕...

    Android学习笔记七:基本视图组件:RadioGroup和RadioButton

    在Android开发中,基本视图组件是构建用户界面的基础,其中RadioGroup和RadioButton是用于创建单选按钮组的重要组件。这篇“Android学习笔记七:基本视图组件:RadioGroup和RadioButton”深入探讨了这两个组件的使用...

    用RadioGroup和ViewPager实现选项卡界面

    本教程将介绍如何利用`RadioGroup`和`ViewPager`来实现这样一个功能。 `RadioGroup`是一个布局容器,用于管理一组单选按钮(RadioButton)。它允许用户在这些按钮中选择一个,并自动处理单选行为。`ViewPager`则是...

    用radiogroup和gridview模拟tabhost

    本文将详细讲解如何使用`RadioGroup`和`GridView`来模拟`TabHost`的功能。 `RadioGroup`是Android中的一个布局容器,用于管理一组单选按钮(RadioButton)。它的主要功能是确保同一时间只有一个单选按钮被选中。而`...

    使用 RadioGroup和TabHost 实现底部菜单栏

    public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.tab1: tabHost.setCurrentTab(0); // 第一个Tab break; case R.id.tab2: tabHost.setCurrentTab(1); // ...

    页面架构1:Fragment+RadioGroup

    总之,使用Fragment和特定的布局组件(如RadioGroup或VideoGroup)可以构建出适应性强、功能丰富的Android页面架构。这种架构设计不仅可以提高代码的可维护性和复用性,还能提供良好的用户体验。开发者应当熟悉这些...

    android RadioGroup实现单选以及默认选中

    在Android开发中,`RadioGroup` 是一个非常重要的布局组件,它主要用于管理一组`RadioButton`控件,确保在同一时间只有一个`...通过以上的介绍和示例,你应该能够熟练地在自己的应用程序中使用`RadioGroup`了。

    弹窗及radiogroup监听事件

    在Android开发中,弹窗(PopupWindow)和RadioGroup控件是两个常用的功能组件,它们在用户界面交互中起着至关重要的作用。本篇将详细探讨这两种组件的使用方法及其相关知识点。 首先,我们来讨论弹窗(PopupWindow...

    RadioGroup组与onCheckedChanged事件

    通过Test6(可能是测试文件或代码示例)了解`RadioGroup`的实战应用,可以更深入地理解其工作原理和使用场景。在项目中,我们可以根据需求自定义`onCheckedChangeListener`,实现更复杂的业务逻辑,比如网络请求、...

Global site tag (gtag.js) - Google Analytics