xml_date

此模板用于将 XML 文件中的字符串根据指定格式转换为日期对象。

dateDate需要格式化的日期。

Example

gantt.templates.xml_date = function(date){
    return gantt.date.date_to_str(gantt.config.xml_date)(date);
};

Details

此模板已废弃。请改用 parse_date

const cfg = gantt.config;
const strToDate = gantt.date.str_to_date(cfg.date_format, cfg.server_utc);
 
gantt.templates.parse_date = function(date){
    return strToDate(date);
};

此模板是从 xml_date 配置自动生成的,可以在 Gantt 初始化 后进行自定义。

如果服务器日期格式不被 Gantt 日期助手 支持,您可以创建自定义模板函数。

例如,当使用 UNIX 时间作为 start_date 时:

/data

{
    "data":[
    {
        "id":1,
        "start_date":1503608400,
        "duration":10,
        "text":"Task #1",
        "parent":0,
    },
    {
        "id":2,
        "start_date":1503694800,
        "duration":4,
        "text":"Task #2",
        "parent":0,
    }],
 
    "links":[
    ]
}

甘特图配置应如下设置:

gantt.attachEvent("onTemplatesReady", function(){
    gantt.templates.xml_date = function(dateString){
        return new Date(dateString * 1000);
    }
});
 
gantt.init("gantt_here");
gantt.load("/data");
See also
Change log

自 v6.2 起废弃,v7.0 中移除

Back to top