日期:2014-05-16  浏览次数:20414 次

extjs 年月日联动下拉框

TimePanel=Ext.extend(Ext.form.FormPanel,{
?constructor:function(){
??TimePanel.superclass.constructor.call(this,{
???border:false,
???defaults:{border:false},
???layout:'column',
???items:[{
????xtype:'combo',
????value:'2011',
????width:60,
????name:'yearcombo',
????store:new Ext.data.SimpleStore({
?????fields:['year'],
?????data:[['2010'],['2011'],['2012'],['2013']]
????}),
????listeners:{'select':this.changeDay},
????mode:'local',
????displayField:'year',
????valueField:'year',
????triggerAction:'all'
???},{
????xtype:'label',
????text:'年'
???},{
????xtype:'combo',
????value:'07',
????name:'monthcombo',
????width:50,
????store:new Ext.data.SimpleStore({
?????fields:['month'],
?????data:[['01'],['02'],['03'],['04'],['05'],['06'],['07'],['08'],['09'],['10'],['11'],['12']]
????}),
????listeners:{'select':this.changeDay},
????mode:'local',
????displayField:'month',
????valueField:'month',
????triggerAction:'all'
???},{
????xtype:'label',
????text:'月'
????
???},{
????xtype:'combo',
????value:'10',
????width:50,
????name:'daycombo',
????store:new Ext.data.SimpleStore({
?????fields:['day'],
?????data:[['01'],['02'],['03'],['04'],['05'],['06'],['07'],['08'],['09'],['10'],
???????['11'],['12'],['13'],['14'],['15'],['16'],['17'],['18'],['19'],['20'],
???????['21'],['22'],['23'],['24'],['25'],['26'],['27'],['28'],['29'],['30'],['31']]
????}),
????mode:'local',
????displayField:'day',
????valueField:'day',
????triggerAction:'all'
???},{
????xtype:'label',
????text:'日'
???}]
??});
?},
?/**
? * 年月变化,改变日
? */
?changeDay:function(){
??//每个月的初始天数??
 ?????????????? MonDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];??
??var year=this.ownerCt.findByType("combo")[0].getValue();
??var month=this.ownerCt.findByType("combo")[1].getValue();
??var n = MonDays[month - 1];??
??if(month=='2'&&isLeapYear(year)){
???n++;
??}
??
??var _store=new Ext.data.SimpleStore({
???fields:['day']
??});
??//填充日期下拉框
??for(var i=1; i<=n; i++)??
???   ????? {??
???   ??????? ?var _record=new Ext.data.Record({'day':i});
??? ??_store.add(_record);
???   ????? }
??? ?this.ownerCt.findByType("combo")[2].store=_store;
??? ?if(this.ownerCt.findByType("combo")[2].view)
??? ??this.ownerCt.findByType("combo")[2].view.setStore(_store);??
?},
?/**
? * 判断是否闰年??
? * @param {} year
? * @return {}
? */
?isLeapYear:function (year)
  ? {???
  ??????? return( year%4==0 || (year%100 ==0 && year%400 == 0));??
  ? }?
});