如何在不使用extjs4中的Ext.getCmp()的情况下启用/禁用表单按钮?

如何在不使用extjs4中的Ext.getCmp()的情况下启用/禁用表单按钮?,extjs,extjs4,Extjs,Extjs4,以下是表单,我想访问表单中的“应用”按钮,而不使用Ext.getCmp()并为按钮定义id: {xtype : 'form', url : 'index.php/submitform', trackResetOnLoad : true, id : 'generalprofilebasicinformation'+ this.getId(), listeners : { //is fired when the form is dirty(field values are modified)

以下是表单,我想访问表单中的“应用”按钮,而不使用Ext.getCmp()并为按钮定义id:

{xtype : 'form',
url : 'index.php/submitform',
trackResetOnLoad : true,
id : 'generalprofilebasicinformation'+ this.getId(),
listeners : {
//is fired when the form is dirty(field values are modified)
    dirtychange : {
        fn : function(sm) {
    //Here Is my problem:
//How to  access to Apply button or any other buttons defined inside the form???
            var applyButton = this.Button;
   applyButton.enable();}}},
   buttons : [{
            text : 'Apply',
            formBind : true, // only
            // enabled
            // once the
            // form is
            // valid
            disabled : true,} ]}

使用构造函数,然后可以在其中创建按钮,然后在表单中引用它。一旦表单中有了引用,就可以从侦听器中检索它。看起来是这样的:

contructor: function(config) {
   this.button = new Ext.Button({
       // Provide your button config here
   });
}

listeners: {
   dirtychange: function(sm) {
       this.button.enable();
   }
}

这在不使用Ext.getCmp()的情况下应该可以工作。

使用构造函数,然后可以在其中创建按钮,然后在表单中引用它。一旦表单中有了引用,就可以从侦听器中检索它。看起来是这样的:

contructor: function(config) {
   this.button = new Ext.Button({
       // Provide your button config here
   });
}

listeners: {
   dirtychange: function(sm) {
       this.button.enable();
   }
}

这在不使用Ext.getCmp()的情况下应该可以工作。

您可以使用控制器侦听此表单触发的“dirtychange”事件

//controller init 
init: function() {
    this.control({
        'form': {
            dirtychange: function(form) {
                var button = form.owner.query('button[text=Apply]');
                button[0].enable();             
            }
        }
    });
}

darren给出的答案肯定会起作用,这只是利用组件查询为您提供了一种访问和控制组件的不同方式。例如,如果希望在表单中启用一系列按钮,可以删除“text=Apply”,并返回所有表单按钮的数组

您可以使用控制器来侦听此窗体触发的“dirtychange”事件

//controller init 
init: function() {
    this.control({
        'form': {
            dirtychange: function(form) {
                var button = form.owner.query('button[text=Apply]');
                button[0].enable();             
            }
        }
    });
}

darren给出的答案肯定会起作用,这只是利用组件查询为您提供了一种访问和控制组件的不同方式。例如,如果希望在表单中启用一系列按钮,可以删除“text=Apply”,并返回所有表单按钮的数组

同意jthirau-明确使用组件查询

另一种方法是简单地添加一个按钮处理程序。这将在按钮配置上显示:

handler:function(){
  //do something
}

同意jthirau-明确使用组件查询

另一种方法是简单地添加一个按钮处理程序。这将在按钮配置上显示:

handler:function(){
  //do something
}

据我所知,当你按下按钮时按钮会被触发,这不是我的情况。无论如何,谢谢。据我所知,当你按下按钮时按钮会被触发,这不是我的情况。无论如何,谢谢