我在我的页面中有一个dhtmlx甘特图,通常它会有完美的工作,但现在当我有一个嵌套数组的JSON文件时,我的输出将是unrecognized
。我正试图填充official name
。dhtmlxgantt填充嵌套的JSON数据
任何人都可以帮助我吗?非常感谢你。
JSON
{
"data": [
{
"assign_to": {
"id": 3,
"employee_id": "28141",
"official_name": "Hal Jordan",
},
"task": {
"id": 1,
"name": "Modeling",
"description": "3d modeling work"
},
"start_date": "2017-06-15",
"end_date": "2017-06-19"
},
{
"assign_to": {
"id": 3,
"employee_id": "28144",
"official_name": "Kyle Rayner",
},
"task": {
"id": 8,
"name": "Composting",
"description": null
},
"start_date": "2017-06-01",
"end_date": "2017-06-08"
}
]
}
的Javascript
gantt.config.columns = [
{name: "assign_to.official_name", label: "Assign To", align: "left", width: 70},
];
function initializeGantt() {
gantt.init("my_scheduler");
gantt.load("/dashboard/ganttchart_list/5/?format=json");
}
initializeGantt();
HTML
<div id="my_scheduler" style='width:1405px; height:245px;'></div>
你好@Alex Klimenkov 非常感谢你,这是完美的!但对于我的数据,它实际上来自REST API,所以如果我想在'getData()'函数中调用,我该如何调用它?例如'http:// 127.0.0.1/test/ganttchart_data/5 /' 再次我可以感谢你足够Alex –
嗨!你可以通过ajax get手动请求你的api,一旦你从服务器获取数据 - 你就可以将它转换成甘特图。 如果您使用上面示例中的jQuery和函数,它可能看起来如下: '$ .get(“/ test/ganttchart_data/5 /”,function(result){ gantt.parse(prepareData(result)); }); ' https://api.jquery.com/jquery.get/ –