2012-09-24 53 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