我想这个问题已经被问了很多(因为我发现了一些关于它的话题),但我仍然不知道如何渲染日期选择器,只显示月份和年份。 我想我可以这样做:
你们可以指导我完成我应该选择的内容,并给我任何可以参考的链接吗?
提前致谢!
答案 0 :(得分:15)
Sencha没有这个组件,但这样的东西我们得到它
Ext.define('Ext.form.field.Month', {
extend: 'Ext.form.field.Date',
alias: 'widget.monthfield',
requires: ['Ext.picker.Month'],
alternateClassName: ['Ext.form.MonthField', 'Ext.form.Month'],
selectMonth: null,
createPicker: function() {
var me = this,
format = Ext.String.format;
return Ext.create('Ext.picker.Month', {
pickerField: me,
ownerCt: me.ownerCt,
renderTo: document.body,
floating: true,
hidden: true,
focusOnShow: true,
minDate: me.minValue,
maxDate: me.maxValue,
disabledDatesRE: me.disabledDatesRE,
disabledDatesText: me.disabledDatesText,
disabledDays: me.disabledDays,
disabledDaysText: me.disabledDaysText,
format: me.format,
showToday: me.showToday,
startDay: me.startDay,
minText: format(me.minText, me.formatDate(me.minValue)),
maxText: format(me.maxText, me.formatDate(me.maxValue)),
listeners: {
select: {
scope: me,
fn: me.onSelect
},
monthdblclick: {
scope: me,
fn: me.onOKClick
},
yeardblclick: {
scope: me,
fn: me.onOKClick
},
OkClick: {
scope: me,
fn: me.onOKClick
},
CancelClick: {
scope: me,
fn: me.onCancelClick
}
},
keyNavConfig: {
esc: function() {
me.collapse();
}
}
});
},
onCancelClick: function() {
var me = this;
me.selectMonth = null;
me.collapse();
},
onOKClick: function() {
var me = this;
if (me.selectMonth) {
me.setValue(me.selectMonth);
me.fireEvent('select', me, me.selectMonth);
}
me.collapse();
},
onSelect: function(m, d) {
var me = this;
me.selectMonth = new Date((d[0] + 1) + '/1/' + d[1]);
}
});
...
Ext.create('Ext.form.field.Month', {
format: 'F, Y',
renderTo: Ext.getBody()
});
答案 1 :(得分:5)
更新到Extjs 5.1: 添加到听众:
afterrender : {
scope : me,
fn : function(c) {
var me = c;
me.el.on("mousedown", function(e) {
e.preventDefault();
}, c);
}
},
防止主场拾取器模糊。在原始版本中,如果你点击月份选择器,它就会失去对日期选择器的关注,所以日期选择器会隐藏所有选择器。