-
29 Nov 2012 3:54 AM #1
Carousel - Problems to add items dinamically into a existing carousel
Carousel - Problems to add items dinamically into a existing carousel
Hello,
I have a carousel in a view, and i want to add items into the carousel. In my controller I get de carousel, and I use the add method to add items, but the new information is not showed.
After that, y press F5 and it works.
My view:
My controller:Code:Ext.define('App.view.name',{ extend: 'Ext.Panel', alias: 'widget.carouselView', config: { ...., items: [ { xtype: 'carousel', cls: 'carrusel-imagenes-ofertas', indicator: true, items: [ ] } ] } });
Thanks,Code:refs: { ......, myCarousel: 'carouselView carousel', }, methodName: function() { var myCarousel = this.getMyCarousel(); myCarousel.removeAll(true); var panelTmp = Ext.create('Ext.Panel', { html: '<img alt="" src= "<img_path>"/>' }); myCarousel.add(panelTmp); myCarousel.setActiveItem(0); }
-
30 Nov 2012 3:09 PM #2
hello,
it's because your ref is not good.
define id in your view :
Then, change your refCode:xtype: 'carousel', id : 'carouselPanel' cls: 'carrusel-imagenes-ofertas', indicator: true
see controller guide : http://docs.sencha.com/touch/2-1/#!/guide/controllersCode:refs: { ......, myCarousel: '#carouselPanel', // add '#' because it's an id }, methodName: function() {var myCarousel = this.getMyCarousel();}
good luck
-
30 Nov 2012 8:34 PM #3
This example of dynamically adding items to a carousel works.
name.js (view)
Main.js (controller):Code:Ext.define('App.view.name', { extend: 'Ext.Panel', xtype: 'carouselView', requires: [ 'Ext.carousel.Carousel' ], config: { layout: 'fit', items: [ { xtype: 'carousel' }, { xtype: 'button', text: 'add', action: 'add', docked: 'bottom' } ] } });
Try this out and see if it works for you. If not, please describe more about your situation. When does the method that dynamically adds items to the carousel run?Code:Ext.define('App.controller.Main', { extend: 'Ext.app.Controller', config: { refs: { myCarousel: 'carouselView carousel' }, control: { 'button[action=add]': { tap: 'handleAddButtonTap' } } }, handleAddButtonTap: function(btn) { var c = this.getMyCarousel(); c.add({ xtype: 'panel', html: new Date(), layout: 'fit' }); } });
BriceBrice Mason
Front End Developer
Modus Create
@bricemason
bricemason.com
Sencha Touch Screencasts
Vimeo - Sencha Touch Channel
Github Projects:
Sencha Cordova Builder enables the automatic creation, building, and running of PhoneGap (Cordova) projects with Sencha Touch.
Am I Sencha Touch Ready? checks your system to determine what you need to do to start Sencha Touch development. If you're having trouble getting up and running, try this out.
Sencha Tools Bridge allows Sencha SDK Tools to co-exist with Sencha Cmd on the same system.
-
1 Dec 2012 5:17 AM #4
Hello Brice,
I tried it, but it didn't work, so I attach my example (without sencha sdk).
¿Could you help me?
Thank you ver much.
-
1 Dec 2012 12:54 PM #5
I changed the type of the Main view. I have used a NavigationView and I have solved the problem.


Reply With Quote