问题 Sencha Touch动态添加项目


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

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,Chrome中)是;

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

显然这不起作用,我做错了什么?


3105
2018-04-13 22:27


起源



答案:


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

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

16
2018-04-14 01:30



谢谢,这是有效的! - Melvin
@ user706933再次感谢您对此的回复,但请将答案标记为正确以关闭该问题。 - sra
谢谢它为我工作 - Abhijit Kurane


答案:


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

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

16
2018-04-14 01:30



谢谢,这是有效的! - Melvin
@ user706933再次感谢您对此的回复,但请将答案标记为正确以关闭该问题。 - sra
谢谢它为我工作 - Abhijit Kurane