id: 'duration',
name: 'duration',
label: '時長',
labelWidth: '35%',
usePicker: true,
listeners: {
'focus' : function(a,e, eOpts) {
Ext.getCmp('duration').setOptions('');
function pad2(d) {
return (d < 10 ? '0' : '') + d;
}
var hours = [];
for (var h = 1; h <= 23; h++) {
hours[hours.length] = {
text: pad2(h),
value: pad2(h)
};
}
var minutes = [];
for (var m = 0; m <= 59; m++) {
minutes[minutes.length] = {
text: pad2(m),
value: pad2(m)
};
}
var picker = Ext.create('Ext.Picker', {
cancelButton: {
text: '取消'
},
doneButton: {
text: '確定'
},
slots: [{
align: 'center',
name : 'hour',
title: '小時',
data: hours,
flex: 2
},{
align: 'center',
name : 'min',
title: '分鐘',
data: minutes,
flex: 2
}],
listeners: {
change: function (picker, newValue, oldValue) {
var optionValue = newValue.hour+':'+newValue.min;
Ext.getCmp('duration').setOptions({text: optionValue, value: optionValue});
},
cancel: function (picker) {
}
}
});
Ext.Viewport.add(picker);
picker.show();
},
initialize: function(s, eOpts){
Ext.getCmp('duration').setOptions({text: '01:00', value: '01:00'});
}
}
如果代碼是自己看着picker 組件寫的,還是有問題的,不夠完美,希望以後能完善一下