2014-02-19 85 views
1

這有點難以解釋,所以我盡我所能,如果我的問題模糊,請要求更清晰。Selectfield偵聽器在視圖初始化時觸發

我使用商店中的選項填充selectfield。該表單在用戶點擊我的一般列表視圖中的某行時獲得的詳細信息中顯示。這一切都完美無缺。

我在我的push()中使用record.data將相關數據傳遞給detailview並使用初始化偵聽器來捕獲此數據並在detailview(標題,表單等)上填充一些項目。

我的selectfield有一個更改偵聽器,在字段更改後執行ajax請求。會發生什麼是我的selectfield首先從商店加載選項,然後初始化偵聽器被調用。

每次加載視圖時都會產生ajax請求。因爲我的初始化偵聽器更改選擇字段以顯示另一個選項爲活動狀態,所以selectfield認爲某些內容已更改並觸發更改偵聽器。

將selectfield選項設置爲活動狀態而不觸發更改偵聽器的最佳方式是什麼?

Selectfield變革聽衆:

xtype: 'selectfield', 
itemId:'groundtype', 
displayField: 'ground_name',  
valueField: 'ground_id', 
store: 'groundTypeStore', 
listeners: { 
    change: function (data) { 
     // execute ajax request on change 
    } 
} 

錶板(的DetailView)初始化監聽

listeners: 
{ 
    initialize: function(){ 
     var value = this.config.record; 

     if(value != null){ 
      this.down('#groundtype').setValue(value.groundtype); 

     } 
    } 
} 

提前感謝!

+0

你使用哪個ExtJS版本? – matt

+0

我使用Sencha/Sencha觸摸。現在將它添加到標籤。 – berentrom

回答

1

,同時通過使用suspendEvents功能設定值可以暫停該領域的事件:

var field = this.down('#groundtype'); 
field.suspendEvents(); 
field.setValue(value.groundtype); 
field.resumeEvents(true); 

注意,你需要通過trueresumeEvents以放棄排隊的事件。

+0

不錯,我想我之前忘記了resumeEvents(true),因爲我試過了,它似乎沒有工作。現在它,謝謝! – berentrom