2011-04-13 98 views
11

如何在Ext.panel中动态添加新项目?这是我正在使用的代码;Sencha Touch动态添加项目

app.views.ViewItem = Ext.extend(Ext.Panel, { 
    id: '0', 
    dockedItems: [{ 
     xtype: 'toolbar', 
     title: 'Melvin test', 
     items: [ 
      { 
       text: 'Terug', 
       ui: 'back', 
       listeners: { 
        'tap': function() { 
         Ext.dispatch({ 
          controller: app.controllers.appController, 
          action: 'backToRssList', 
          animation: {type:'slide', direction:'right'} 
         }); 
        } 
       } 
      }, 
      {xtype:'spacer'}, 
      { 
       id: 'share', 
       text: 'Delen', 
       ui: 'action', 
       listeners: { 
        'tap': function() { 
         Ext.dispatch({ 
          controller: app.controllers.appController, 
          action: 'share', 
         }); 
        } 
       } 
      } 
     ] 
    }], 
    items: [], 
    initComponent: function() { 
     app.views.ViewItem.superclass.initComponent.apply(this, arguments); 
    }, 
    getView: function(data) { 
     //this.items.add({html: 'test'}); 
    }, 
}); 

在函数getView中,我试图用这行添加一个新项目;

this.items.add({html: 'test'}); 

被显示出来的错误(在RockMelt的,铬)是;

Uncaught TypeError: Object #<Object> has no method 'getItemId' 

显然这是行不通的,我做错了什么?

回答

16

您是否尝试使用面板本身的add()函数?例如:

this.add({html: 'test'}); 
+0

谢谢,这是工作! – Melvin 2011-04-14 19:13:46

+0

@ user706933再次感谢您对此的回复,但请将答案标记为正确以解决问题。 – sra 2011-04-28 21:21:12

+0

感谢它为我工作 – 2015-01-06 10:09:59