2012-05-01 19 views
0

我剛開始使用Sencha Architect,即使是最簡單的事情,我也遇到了問題。我正在嘗試進入下一個視圖,點擊一個按鈕時。到目前爲止,我點擊該按鈕時的代碼會發出警報。在Sencha Architect的按鈕事件中顯示視圖

Ext.define('MyApp.view.Login', { 
    extend: 'Ext.Container', 

    config: { 
     layout: { 
      align: 'center', 
      type: 'vbox' 
     }, 
     items: [ 
      { 
       xtype: 'fieldset', 
       width: 500, 
       title: 'Login', 
       items: [ 
        { 
         xtype: 'selectfield', 
         label: 'Vælg bil', 
         store: 'cars' 
        }, 
        { 
         xtype: 'passwordfield', 
         label: 'Adgangskode' 
        }, 
        { 
         xtype: 'checkboxfield', 
         label: 'Husk mig' 
        }, 
        { 
         xtype: 'button', 
         handler: function(button, event) { 
          alert("foo"); 
         }, 
         text: 'Log ind' 
        } 
       ] 
      } 
     ] 
    } 

}); 

什麼應該去而不是警報,添加一個新的視圖?

回答

0

你可以使用這個打開的視圖ID爲「sampleview」:

if(Ext.getCmp('sampleview')) 
{ 
    Ext.Viewport.setActiveItem(Ext.getCmp('sampleview')); 
} 
else 
{ 
    var sample = Ext.create('App.view.SampleView'); 
    Ext.Viewport.setActiveItem(sample); 
} 
+0

我不能得到這個工作。我給了我的容器id'sampleview',但事件觸發時沒有任何反應。甚至沒有在控制檯中的錯誤。我的項目位於https://github.com/danielsvane/senchaviewtest。你可以看一下嗎?謝謝。 – danielsvane

+0

沒關係,你是對的,我只是沒有正確使用它。爲什麼有必要創建關於事件的觀點?有沒有辦法在之前創建它,只需使用'Ext.Viewport.setActiveItem(Ext.getCmp('sampleview'));'? – danielsvane

+0

我檢查了你的代碼,但是因爲我看到你只使用了上面代碼的一行。你可以簡單地寫: 'var sample = Ext.create('App.view.SampleView'); Ext.Viewport.setActiveItem(樣品);' 代替: 'Ext.Viewport.setActiveItem(Ext.getCmp( 'sampleview'));' 我寫上面如果條件只是爲了避免多重創建的看法。 – mostar

相關問題