2011-04-13 8 views
11

¿Cómo puedo agregar dinámicamente un nuevo elemento en Ext.panel? Este es el código que estoy usando;Sencha Touch agregar elementos dinámicamente

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'}); 
    }, 
}); 

En la función getView, intento agregar un nuevo elemento con esta línea;

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

El error que se muestra (en Rockmelt, Chrome) es;

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

Obviamente esto no funciona, ¿qué estoy haciendo mal?

Respuesta

16

¿Intentó utilizar la función add() para el panel? E.g:

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

Gracias, eso está funcionando! – Melvin

+0

@ user706933 gracias de nuevo por la respuesta al respecto, pero marque la respuesta como correcta para cerrar la pregunta. – sra

+0

Gracias es que funciona para mí –