当前位置: 代码迷 >> Web前端 >> Sencha Touch 二 Carousel 模仿list itemtap
  详细解决方案

Sencha Touch 二 Carousel 模仿list itemtap

热度:510   发布时间:2012-07-31 12:33:46.0
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);
	}
});




  相关解决方案