2012-09-24 127 views
1

我試圖initialize()destroy()動態地從導航視圖的另一個視圖欄上的按鈕。按鈕創建正常,但我不能刪除它...也試過hide(),但它被稱爲兩次,並沒有幫助。所以我正式卡住了,請幫忙! :-)導航視圖上的Sencha Touch 2動態按鈕

我的控制器:

Ext.define('MyApp.controller.Application', { 
    extend: 'Ext.app.Controller', 

    config: { 
     refs: { 
      buttonNew1: '#btn-new1', 
      buttonNew2: '#btn-new2', 
      buttonNew3: '#btn-new3', 
      buttonNew4: '#btn-new4', 
      buttonDataNew: '#btn-data-new' 
     }, 

     control: { 
      buttonNew1: { tap: 'onNewButtonTap' }, 
      buttonNew2: { tap: 'onNewButtonTap' }, 
      buttonNew3: { tap: 'onNewButtonTap' }, 
      buttonNew4: { tap: 'onNewButtonTap' }, 
      buttonDataNew: { tap: 'onDataNewButtonTap' }, 
     } 
    }, 

    onNewButtonTap: function(button) { 
     console.log(button); 
    }, 

    onDataNewButtonTap: function(button) { 
     console.log(button); 
    } 
}); 

我的導航視圖:

Ext.define('MyApp.view.Main', { 
    extend: 'Ext.navigation.View', 
    xtype: 'view-main', 

    config: { 
     autoDestroy: false, 

     items: [ 
      { 
       xtype: 'container', 
       layout : { type: 'vbox', pack: 'top', align: 'middle' }, 

       items: [ 
        { 
         xtype: 'container', 
         layout: 'hbox', 

         items: [ 
          { 
           xtype: 'button', 
           id: 'btn-new1', 
           text: 'New1' 
          }, 
          { 
           xtype: 'button', 
           id: 'btn-new2', 
           text: 'New2' 
          } 
         ] 
        }, 
        { 
         xtype: 'container', 
         layout: 'hbox', 

         items: [ 
          { 
           xtype: 'button', 
           id: 'btn-new3', 
           text: 'New3' 
          }, 
          { 
           xtype: 'button', 
           id: 'btn-new4', 
           text: 'New4' 
          } 
         ] 
        } 
       ] 
      } 
     ] 
    } 
}); 

我的數據視圖:

Ext.define("MyApp.view.Data", { 
    extend: 'Ext.dataview.DataView', 
    xtype: 'view-data', 

    config: { 
     useComponents: true, 
     layout: { type: 'fit', align: 'center' }, 
     defaultType: 'view-data-item', 
     store: 'MyStore' 
    }, 

    initialize: function() { 
     this.callParent(); 
     Ext.Viewport.getActiveItem().getNavigationBar().add(Ext.create('Ext.Button', { 
      id: 'btn-data-new', 
      ui: 'normal', 
      iconCls: 'add1', 
      align: 'right', 
      iconMask: true, 
      hideAnimation: Ext.os.is.Android 
       ? false : { type: 'fadeOut', duration: 200 }, 
      showAnimation: Ext.os.is.Android 
       ? false : { type: 'fadeIn', duration: 200 } 
     })); 
    }, 

    destroy: function() { 
     this.callParent(); 
     var button = Ext.getCmp('btn-data-new'); 
     if (button) { 
      Ext.Viewport.getActiveItem().getNavigationBar().remove(button); 
     } 
    } 
}); 

回答

1

好吧,我想通它終於出來了......問題是在導航視圖autoDestroy: false

+0

感謝此代碼。你有沒有讓showAnimation和hideAnimation工作?我的似乎沒有工作。 – dmackerman