Sencha Touch 2 Carousel 模仿list itemtap
/** * @Author sai * Carousel 模仿list itemtap事件 */ Ext.define('SmartMenu.view.tips.Carousel', {extend: 'Ext.Carousel',xtype:'myCarousel',requires: ['Ext.carousel.Carousel',],config: { direction: 'horizontal', listeners: {'initialize':function(carousel){Ext.getStore('Pictures').load(function(pictures) {var myitems = [];Ext.each(pictures, function(picture) {if (!picture.get('image_url')) {return;}myitems.push({xtype:'panel', listeners : { painted : function(panel) { var el = panel.element; el.on('tap', function(e, t) { this.getParent().onTap(picture.data.id); }, panel); } },items:[{html:'<img src="'+picture.data.image_url[0]+'"/>'+'<br>'+picture.data.title } ]});}); carousel.setItems(myitems); setInterval(function(){if(i<carousel.getItems().length) { i+=1; carousel.setActiveItem(i); } else { carousel.setActiveItem(0); i=0; }},1000);});}},},onTap:function(id){//debugger; var store= Ext.getStore('Pictures'); var data=store.findRecord('id',id).getData();var menu= Ext.create('SmartMenu.view.tips.SeasonDetails',{fullscreen: true,data: data}); Ext.getCmp('home_nav').setActiveItem(menu);}});