我对Javascript比较陌生,并且在我的网站上使用JSGantt.js作为甘特图。 html页面上唯一需要的代码如下所示:
<div style="position:relative" class="gantt" id="GanttChartDIV"></div>
<script>
// here's all the html code neccessary to display the chart object
// Future idea would be to allow XML file name to be passed in and chart tasks built from file.
var g = new JSGantt.GanttChart('g',document.getElementById('GanttChartDIV'), 'quarter');
g.setShowRes(0); // Show/Hide Responsible (0/1)
g.setShowDur(0); // Show/Hide Duration (0/1)
g.setShowComp(0); // Show/Hide % Complete(0/1)
g.setCaptionType('None'); // Set to Show Caption (None,Caption,Resource,Duration,Complete)
g.setShowStartDate(0); // Show/Hide Start Date(0/1)
g.setShowEndDate(0); // Show/Hide End Date(0/1)
//var gr = new Graphics();
if( g ) {
// Parameters (pID, pName, pStart, pEnd, pColor, pLink, pMile, pRes, pComp, pGroup, pParent, pOpen, pDepend, pCaption)
// You can also use the XML file parser JSGantt.parseXML('project.xml',g)
g.AddTaskItem(new JSGantt.TaskItem(1, 'Title', '', '', '52A3CC', 'http://www.google.com', 0, 'Team Leader Name', 100, 1, 0, 1));
g.Draw();
g.DrawDependencies();
}
else {
alert("not defined");
}
</script>
在g.AddTaskItem函数中,它期望在页面中键入日期。我想在它的位置使用现有的日期变量。
我怎样才能做到这一点?谢谢你的帮助!如果你想看到提取这些信息的.js文件,请点击这里:
答案 0 :(得分:0)
假设它想要一个好的ISO标准日期字符串,你可以这样做:
function getDate (days) {
if (typeof days === "undefined") {
var days = 0;
}
var date = new Date();
return new Date(date.valueOf() + days*86400000).toISOString().substring(0,10);
}
<snip>
g.AddTaskItem(new JSGantt.TaskItem(1, 'Title', getDate(-30), getDate(), '52A3CC', 'http://www.google.com', 0, 'Team Leader Name', 100, 1, 0, 1));
<snip>
getDate([optional number])
将返回今天的日期,这个日期可以根据您提供的天数进行调整 - 或者如果没有给出的参数将在今天返回。理论上你可以在那里做任何功能。如果这不是正确的日期格式,您可以使用toISOString().substring(0,10)
或其中一个date functions而不是toDateString()
。如果你想要,你当然可以调整功能甚至在运行时询问用户日期。