-
13 Feb 2012 2:16 PM #1
Answered: Move items from store to carousel
Answered: Move items from store to carousel
I have manage to use a listener to fetch the data i want from a store but cant figure out how to move it to the carousel i defined. Ive looked at the examples in the download files that comes with sencha but cant change my code to match it. Can anyone point me in the right direction?
My view:
Code:var carousel = Ext.define('App.view.Products', { extend: 'Ext.Carousel', xtype: 'productspage', config: { title: 'Product', iconCls: 'star', defaults: { styleHtmlContent: true } } }); var myStore = Ext.create('Ext.data.Store', { model: 'App.model.Event', autoLoad: true, proxy: { type: 'scripttag', url : url }, listeners: { load: function(store, records, index) { items = []; for (var i=0; i<records.length; i++) { items.push({ xtype: 'image', cls: 'my-carousel-item-img', html: '<img src="' + records[0].data.event_image + '">' }); } } } });
-
Best Answer Posted by mitchellsimoens
If you have the carousel already created, then right after your for loop you can do this:
items can be a single object or an array of objects like in your case.Code:carousel.add(items);
If the carousel is not created then you need to create the carousel:
Of course you may need fullscreen or add the carousel to a component or whatever your application needs.Code:new Ext.carousel.Carousel({ items : items });
-
14 Feb 2012 6:18 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 435
- Answers
- 3102
So after your for loop in the store's load listener is where you would either create the carousel or if the carousel is already created then you can simple add the items array to the carousel.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
15 Feb 2012 1:05 AM #3
-
15 Feb 2012 4:31 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 435
- Answers
- 3102
If you have the carousel already created, then right after your for loop you can do this:
items can be a single object or an array of objects like in your case.Code:carousel.add(items);
If the carousel is not created then you need to create the carousel:
Of course you may need fullscreen or add the carousel to a component or whatever your application needs.Code:new Ext.carousel.Carousel({ items : items });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
15 Feb 2012 4:34 AM #5
Looking at the code you supplied, I think I found an error in there somewhere. I think you should have the i (marked with red in the code below), to not just add the first record in your results to the array.
Code:listeners: { load: function(store, records, index) { items = []; for (var i=0; i<records.length; i++) { items.push({ xtype: 'image', cls: 'my-carousel-item-img', html: '<img src="' + records[i].data.event_image + '">' }); } } }Last edited by msweltzdk; 15 Feb 2012 at 4:40 AM. Reason: removed advice on adding view to carousel, mitchellsimoens was faster.
-
15 Feb 2012 5:40 AM #6
-
15 Feb 2012 5:41 AM #7
Np, I just hoped that it could clear some possible headaches in the future if you encountered any errors.




Reply With Quote