添加元素到carousel sencha

时间:2011-05-31 14:54:55

标签: add elements extjs carousel

sencha touch 中,我有一个如下声明的轮播:

ajaxNav = new Ext.Panel({    
    scroll: 'vertical',
    cls: 'card1 demo-data',
    styleHtmlContent: true,
    layout: {
        type: 'vbox',
        align: 'stretch'
    },
    defaults: {
        flex: 1
    },
    items: [{
        xtype: 'carousel',
        items: [{
            id:'tab-1',
            html: '',
            cls: 'card card1'
        },
        {
            id:'tab-2',
            html: '<p>Clicking on either side of the indicators below</p>',
            cls: 'card card2'
        },
        {
            id:'tab-3',
            html: 'Card #3',
            cls: 'card card3'
        }]
    }]
});

有人知道如何添加dinamycally元素吗?

1 个答案:

答案 0 :(得分:6)

我写了一个简单的例子,向您展示如何将新面板添加到现有的Ext.Carousel元素中。

Ext.setup({

onReady: function() {

    var ajaxNav = new Ext.Carousel({    
        fullscreen: true,
        dockedItems: {
            xtype: 'toolbar',
            title: 'Demo',
            items: [{
                xtype: 'button',
                ui: 'action',
                text: 'Add',
                handler: function(){

                    var element = new Ext.Panel({
                        html: 'New Element'
                    });

                    ajaxNav.add(element);
                    ajaxNav.doLayout();

                }
            }]
        },
        items: [{
            id:'tab-1',
            html: '',
            cls: 'card card1'
        },{
            id:'tab-2',
            html: '<p>Clicking on either side of the indicators below</p>',
            cls: 'card card2'
        },{
            id:'tab-3',
            html: 'Card #3',
            cls: 'card card3'
        }]
    });

}

});

正如您所看到的,在“添加”按钮事件中,您首先必须根据需要定义面板,然后将其添加到您的旋转木马,最重要的是,您必须让旋转木马重新计算他的布局调用了“doLayout()”函数。

希望这有帮助。