2010-07-16 17 views
1

再次我可能是愚蠢的,我遇到對象的偵聽器事件的麻煩。關於選擇/點擊事件的一個Ext.RadioGroup

我:

new Ext.form.Radio({ 
        boxLabel:'Yes', 
        id: 'car_price_type_yes', 
        name: 'car_price_type', 
        value: 1, 
        listeners: { 
         select: function (e) { 
          alert('x'); 
         } 
        } 
       }) 

我試圖讓當我點擊單選按鈕,出現警報。

謝謝。

回答

-2

你想要check事件。你真的應該更熟悉docs,它會幫助解決這類問題。

編輯:似乎人們不滿意這個答案。好的,從Ext 4.x開始,似乎change事件就是你想要的收音機/複選框。

+0

感謝。對不起,但當我更改'選擇'來檢查時,我仍然沒有得到警報。我也試着把它放在聽衆大括號之外。 – babadbee 2010-07-16 16:24:09

+0

您必須有其他問題,因爲我複製了上面的代碼,將事件更改爲「檢查」,並且按預期得到了警報。 – 2010-07-16 17:57:25

+0

如果你的extjs文檔沒有吸得這麼糟糕,這不會很難弄清楚。您的文檔http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.form.field.Radio沒有單選按鈕上的檢查事件。 – boatcoder 2013-05-20 14:25:54

1

問題出在單選按鈕作爲某種非常規實體的處理。他們似乎根本不是電話聽衆。

在涉及文檔,論壇,源代碼和其他所有內容之後,我偶然提到了處理程序方法,並且似乎您必須聲明它們具有處理程序(如下所示),如果要檢測「點擊「事件」或「更改」事件或「選擇」事件。唯一能夠讓4.1.3實際產生的「事件」是調用我的處理函數,其他事件名稱都不會產生任何東西。文檔中的許多人指出,變化並不總是會發生,我從來沒有設法根本解決它。

{ 
    boxLabel: 'Field Based' 
    , name: 'alert_type' 
    , inputValue: 'field' 
    , xtype: "radiofield" 
    , listeners: { 
     // won't be called 
     click: function(a,b,c,d) { 
      console.log("FB",a,b,c,d); 
     } 
     // won't be called 
     ,change: function(a,b,c,d) { 
      console.log("Change",a,b,c,d); 
     } 
     // won't be called 
     , select: function(field, newValue, oldValue) { 
      console.log(field, "Radio Selected ", newValue, "to", oldValue); 
     } 
     // won't be called 
     , check: function(field, newValue, oldValue) { 
      console.log(field, "Radio Checked ", newValue, "to", oldValue); 
     } 
    } 
    // WILL BE CALLED 
    , handler: function(field, state) { 
     console.log(field, state, c, d) 
    } 
}, 

的處理器將產生日誌輸出,如:

constructor {boxLabel: "Field Based", name: "alert_type", inputValue: "field", listeners: null, handler: function…} 
true