`
hrl_100_eyejava
  • 浏览: 23211 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

extjs中fieldset控件中选中和取消标题上的checkbox

    博客分类:
  • js
 
阅读更多

     因公司项目需要引入了extjs中fieldset,要求在页面载入的时候选中或者取消fieldset控件中选中和取消标题上的checkbox,api文档中有个toggleCollapse()方法。不过,用的不太理想,总是当关闭的时候再调用则会打开,反之亦然;翻来下源码

 toggleCollapse : function(animate){
        this[this.collapsed ? 'expand' : 'collapse'](animate);
        return this;
    }

 不难看出是调用expand(alimate)或者collapse(alimate)方法。

alimate为true,使用动画效果,也即动作慢慢的滑动;

alimate为false,不使用动画效果,此时动作会很快。

 

具体例子如下:

Ext.onReady(function(){

    var fsf = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        url:'save-form.php',
        frame:true,
        title: 'Simple Form with FieldSets',
        bodyStyle:'padding:5px 5px 0',
        width: 500,

        items: [{
			id : 'fs',
            xtype:'fieldset',
            checkboxToggle:true,
            title: 'User Information',
            autoHeight:true,
            defaults: {width: 210},
            defaultType: 'textfield',
            collapsed: true,
            items :[{
                    fieldLabel: 'First Name',
                    name: 'first',
                    allowBlank:false
                },{
                    fieldLabel: 'Last Name',
                    name: 'last'
                },{
                    fieldLabel: 'Company',
                    name: 'company'
                }, {
                    fieldLabel: 'Email',
                    name: 'email',
                    vtype:'email'
                }
            ]
        }],

        buttons: [{
            text: '选中并打开(动画)',
			handler : function() {
				var fs = Ext.getCmp('fs');
				fs.expand(true);
			}
        },{
            text: '不选并关闭(动画)',
			handler : function() {
			   var fs = Ext.getCmp('fs');
			   fs.collapse(true);
			}
        },{
            text: '选中并打开(普通)',
			handler : function() {
				var fs = Ext.getCmp('fs');
				fs.expand(false);
			}
        }, {
		    text: '不选并关闭(普通)',
			handler : function() {
			   var fs = Ext.getCmp('fs');
			   fs.collapse(false);
			}
		}]
    });

    fsf.render(document.body);

   
   
});

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics