添加元素到carousel sencha

Jos*_*los 2 extjs add elements 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'
        }]
    }]
});
Run Code Online (Sandbox Code Playgroud)

有谁知道如何添加dinamycally元素?

小智 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'
        }]
    });

}
Run Code Online (Sandbox Code Playgroud)

});

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

希望这可以帮助.