2011-09-22 70 views
0

我有一個簡單的例子,這裏是一個'視圖'的模式窗口。我想在窗口內有一個窗口關閉窗口,所以懶惰的用戶不需要點擊右上角的'X'。Extjs 4.0 MVC - 如何關閉控制器內的視圖?

我的問題是我不知道如何從控制器內引用視圖。在非MVC世界中,我只需在按鈕處理程序中執行'window.close()'。有任何想法嗎?謝謝!

查看

Ext.define('AM.view.testwindow.window', { 
    extend: 'Ext.window.Window', 
    alias: 'widget.TESTwindow', 
    title: 'TEST Window', 
    layout: 'border', 
    width: 1000, height: 400, 
    minimizable: true, 
    maximizable: true, 
    closeAction: 'destroy', 
    initComponent: function() { 
     this.items = [ 

     {xtype: 'gridpanel', region: 'center', // grid in the window 
     store: 'Equipments', 
     columns: [ 
      { text: 'Equip ID', dataIndex: 'EquipmentID' } 
      , { text: 'StationID',  dataIndex: 'StationID' } 
     ], 

     dockedItems: [{ 
      xtype: 'toolbar',   // Grid's toolbar 
      items: [ 
      { 
        xtype: 'button',    /* Close button to close the window */ 
        text: 'Close Window', 
        itemId: 'btnTestClose' 
       } 
      ] 
     } 
     ] 
    } 
    ]; 
    this.callParent(arguments); 
} 
}); 

控制器從按鍵處理程序中的 '這'

Ext.define('AM.controller.testwindow', { 
    extend: 'Ext.app.Controller', 
    stores: ['Equipments', 'Stations'], 
    models: ['Equipment'], 
    views: ['testwindow.window', 'testwindow.Grid'], 
    refs: [ 
    {  ref: 'TESTgrid',  selector: 'TESTgrid' }, 
     { ref: 'testwindow', selector: 'testwindow' } 
    ], 

    init: function() { 

     this.control(
     { 
      '#btnTestClose': { 
       click: function (butt, e, options) { 
        alert('close handler!'); 
        this.getTestwindowWindowView().close(); // this fails. What should I do? ComponentQuery ? 
       } 
      } 

     } 
     ) 
    } 
} 
); 

範圍

Scope of 'this' from within Button handler

回答

1

ref的測試窗口應該匹配別名TESTwindow(不widget部分),也可能長名稱testwindow.window

refs: [ 
    { ref: 'TESTgrid',  selector: 'TESTgrid' }, 
    { ref: 'TESTwindow', selector: 'testwindow' } 
], 

這會給你你需要自動生成的getter:

this.getTestwindow().close(); 

吸氣器由get加上帶大寫第一個字母的參考選擇器組成。

+0

是的......昨晚想通了。我認爲引用只是訪問組件的簡短方式,但實際上它們允許硬件引用組件。感謝您的回答! – amackay11

-1
refs: [ 
    { ref: 'TESTgrid',  selector: 'TESTgrid' }, 
    { ref: 'win', selector: 'testwindow' } 
], 

Try this 

this.getWin().close(); 


ready ok 
+0

請[編輯]解釋爲什麼/如何代碼回答這個問題?不提供代碼的答案是不鼓勵的,因爲它們不像代碼解釋那樣容易學習。沒有解釋,需要花費更多的時間和精力去理解正在做什麼,對代碼所做的修改,代碼是否回答問題等等。對於試圖從答案中學習的人以及那些評估回答是否有效,或值得投票。 – Makyen

+0

請寫一些描述/評論,以便用戶能夠理解。 –

相關問題