如何在以下代码中将Value和minValue属性设置为下一个星期六?
我想要在日期字段中将默认显示日期设置为星期六的日期。假设今天是08/09/2018,默认值显示应该是08/11/2018。您可以在Sencha fiddler中运行以下代码:
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.create('Ext.form.field.Date', {
value: Ext.Date.add(new Date, Ext.Date.DAY, 6), // defaults to today
minValue: Ext.Date.add(new Date(), Ext.Date.DAY, 6),
renderTo: Ext.getBody()
});
}
});
答案 0 :(得分:1)
这是类似这样的工作版本:
Ext.application({
name: 'Fiddle',
launch: function() {
function getNextDayOfWeek(date, dayOfWeek) {
var resultDate = new Date(date.getTime());
resultDate.setDate(date.getDate() + (7 + dayOfWeek - date.getDay()) % 7);
return resultDate;
}
var nextSaturday = getNextDayOfWeek(new Date(), 6)
Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
width: 300,
bodyPadding: 10,
title: 'Date',
items: [{
xtype: 'datefield',
anchor: '100%',
fieldLabel: 'From',
name: 'from_date',
value: nextSaturday,
minValue: nextSaturday
}]
});
}
});