1
votes

I would like to reload items in the carousel onPainted() method. So whenever users come the carousel item then we have a fresh list of carousel items. Problem at this point of time (please have a look at the source code), the carousel reloads items, however until I touch the carousel, the first carousel item is blank (or not selected) and no items selected. I would like at least to see the first element to be selected.

So here is the simplified source code:

Ext.define("APN.view.FeaturedCarousel", {
    config: {
        listeners: {
            painted: function(carousel, eOpts) {
                var features_url = Ext.getStore("regionalisation").getRegionalisedMenus().feature.url;
                this.setCarouselStore(features_url);
            }
        }
    },
    initialize: function () {
        this.callParent();
        var me = this;
        var features_url = Ext.getStore("regionalisation").getRegionalisedMenus().feature.url;
        this.setCarouselStore(features_url);
    },
    setCarouselStore: function (features_url) {
        var me = this;

        Ext.Ajax.request({
            url: features_url,
            success: function (response) {
                me.removeAll();
                if (!xml) return;

                var store = Ext.create('Ext.data.Store', {
                    autoLoad: true,
                    fields: [
                    ],
                    data: xml,
                    proxy: {
                        type: 'memory',
                        reader: {
                            type: 'xml',
                            rootProperty: 'xml',
                            record: 'item'
                        }
                    }
                });

                store.each(function (record) {
                    var item = Ext.create("Ext.Container", {
                        html: "some HTML HERE"
                    });

                    me.add(item);
                });
            }
        });
    }
});
1

1 Answers

1
votes

I think you should activate the first item in the carousel once all the items are added. Like this:

  store.each(function (record) {
    var item = Ext.create("Ext.Container", {
      html: "some HTML HERE"
    });

    me.add(item);
  });

  me.setActiveItem(0);

This should make the first item selected.

If you want to change the carousel content every time it is activated, use "active" listener. Because "painted" will be called only once and if you want that, then no point in adding a painted event because you are already calling the "setCarouselStore" function in "initialize" method.