【发布时间】:2015-04-22 18:02:12
【问题描述】:
我正在尝试按日期确定项目是否到期。在我的用例中,我的用户将创建一个具有以下格式(MM/DD 或 06/15)日期的项目。现在,如果用户选择的日期将在接下来的 30 天或一个月内,那么它将变成红色。如果日期将在接下来的 60 天或更短的时间内(直到达到 30),则它将为橙色,如果大于 60,则为黄色。
所以澄清一下,如果我的日期
我正在研究 Date.js 以执行这些计算,但不确定如何开始。
到目前为止,我的想法如下:
var _dueDate = CurrentItem.DateNeeded; //not sure if this is correct syntax for SharePoint development
var now = Date();
var nowPlus30 = new Date();
nowPlus.setDate(now.getDate() + 30);
var nowPlus90 = new Date();
nowPlus.setDate(now.getDate() + 90);
if (_dueDate == '' || !_dueDate) {
return '';
}
and then just using the values to change the background color for example:
if( _dueDate <= nowPlus30 ) //find the data to use to determine the color
{
x[i].parentNode.style.backgroundColor = 'orange'; // set the color
}
但是到目前为止,为每个条件执行这些操作还没有奏效,所以我认为使用 Date.js 可能会有所帮助,但不知道如何继续,因为我不能使用 SharePoint 设计器来使用那些我必须使用的内置条件语句使用javascript进行操作。以前曾问过这个问题,但我认为这更像是我遇到的 JavaScript 问题,而不是 SharePoint 问题。
请帮忙!
【问题讨论】:
-
_dueDate 似乎总是今天的日期。您是否在其他地方为其分配了另一个值?
-
@Robbert,好的,是的,这是有道理的。截止日期应该是用户在项目中提供的日期。所以真的会是例如:CurrentItem.DateNeeded,格式为 04/15。
-
04/15 是否等于 4/1/2015?或者它是否意味着一个月的最后一天?还是中间?为什么不将日期存储为实际日期而不是仅存储月份和年份?
-
@Robbert,对于我的表单,用户需要该格式的日期。但是,如果在代码中我们可以说它的格式是 04/15,那么它实际上等于 04/01/2015。有什么想法吗?
标签: javascript jquery html date sharepoint