Extjs 4.1 datefield - 设置本周的第一天和最后一天

标签 extjs extjs4.1

我尝试在 http://jsfiddle.net/uXkNr/ 中创建一个带有 2 个日期字段的表单面板

这是我的元素

items: [{
        xtype: 'datefield',
        labelWidth: 50,
        format: 'd/m/Y',
        fieldLabel: 'From',
        name: 'from_date',
        value: new Date()  // First day of current week
    }, {
        xtype: 'datefield',
        labelWidth: 50,
        fieldLabel: 'To',
        format: 'd/m/Y',
        name: 'to_date',
        value: new Date()  // Last day of current week
    }]

我尝试设置本周的第一天和最后一天。示例

enter image description here

今天是:2013 年 10 月 15 日(日/月/年)。那么 From 的日期为:14/10/2013,To 的日期为:20/10/2013。

这可能吗?怎么做谢谢。

最佳答案

未经测试:

var now = new Date(),
    startDay = 1, // monday
    currDay = now.getDay(),
    start = now,
    eDate = Ext.Date,
    sub, end;

eDate.clearTime(now);
if (currDay !== startDay) {
    // Sunday
    if (currDay === 0) {
        sub = 6;
    } else {
        sub = currDay - startDay;
    }
    start = eDate.add(now, eDate.DAY, -sub);
}
end = eDate.add(start, eDate.DAY, 6);
console.log(start, end);

关于Extjs 4.1 datefield - 设置本周的第一天和最后一天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19375771/

相关文章:

Extjs - 工具栏而不是标题(启用选项可折叠)

javascript - Extjs + PHP 通过增加 Java 堆大小来增强性能

css - Ext JS on rowdblclick 更改点击的行背景颜色

grails - Chrome开发人员工具显示Grails应用程序中动态生成的文件的下载状态已取消

extjs - 在 ExtJS 中覆盖类/属性的最佳实践?

javascript - EXTJS 4.1 如何选择树面板中的下一个叶节点

Extjs 4.1 提交表单 - 如何在 xtype : displayfield 中获取值

ExtJS 4.2 文件字段多重上传

javascript - 在Sencha Touch中获取容器在 "initialize"上的记录

javascript - Extjs 4 上传成功函数没有反应