2012-02-03 21 views
2

這裏是下面的表格,我想訪問form`s表單內應用按鈕,而無需使用Ext.getCmp(),並定義一個ID爲按鈕:如何在extjs4中不使用Ext.getCmp()來啓用/禁用窗體按鈕?

{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,} ]} 

回答

2

您可以使用一個控制器來監聽通過這種形式打響了「dirtychange」事件。

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

達倫給了肯定的工作答覆,這只是利用組件查詢給你一個不同的方式來達到和控制元件。如果你想在窗體中啓用一系列的按鈕,例如,你可以刪除「文本=應用」和所有形式的按鈕的陣列將被退回。

1

使用構造函數,然後就可以創建按鈕,然後在你的窗體中引用它。一旦你有了表單中的引用,你就可以從你在那裏的偵聽器中檢索它。應該是這樣的:

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

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

這應該不使用Ext.getCmp工作()

1

同意jthirau - 絕對使用組件查詢。

另一種做你正在做的事情的方法是簡單地添加一個按鈕處理程序。這正好對上按鈕的配置:

handler:function(){ 
    //do something 
} 
+0

像我知道,當你按下按鈕,該按鈕就會被觸發,這是不是我的case.Thanks反正 – 2012-02-06 19:09:56