1
試圖讓dhtmlx甘特圖加載json數據加載頁面。dhtmlx甘特使用jquery動態加載數據
data_file.php(SNIP)
$colors = array(1=>"red", 2=>"green", 3=>"blue", 4=>"yellow", 5=>"orange", 6=>"grey");
$aryData = array();
if($project_tasks) {
foreach($project_tasks as $aryTask) {
$aryData[] = array(
"id" => $aryTask["pt_id"],
"text" => $aryTask["pt_name"],
"start_date" => date("d-m-Y", strtotime($aryTask["pt_start_date"])),
"duration" => round((strtotime($aryTask["pt_end_date"]) - strtotime($aryTask["pt_start_date"]))/(60*60)),
"open" => true,
"color" => $colors[rand(1,6)]
);
}
}
$strData = json_encode($aryData, JSON_UNESCAPED_SLASHES);
header("Content-type:application/json;");
echo "\"data\" : ".$strData;
提供了這樣的事情(從鉻控制檯):
"data" : [{"id":"152","text":"test3","start_date":"01-09-2015","duration":600,"open":true,"color":"yellow"},{"id":"153","text":"test1","start_date":"23-09-2015","duration":72,"open":true,"color":"grey"},{"id":"154","text":"test2","start_date":"15-09-2015","duration":264,"open":true,"color":"red"}]
JS-file.js(中略)
var data_url = basePath + "system/data_file.php?project_id=" + projectID;
$(".gantt").dhx_gantt({
scale_unit:"week",
step:1,
date_scale:"%W"
});
// var tasks = $(".gantt").dhx_gantt().load(data_url);
$(".gantt").dhx_gantt().load(data_url);
gantt.parse(tasks);
我嘗試「提醒(任務)」;「結果爲「未定義」或爲空。
我已經試過數據syncronous AJAX負荷:
var tasks = null;
$.ajax({
url: data_url,
async: false,
dataType: 'json',
success: function(data) {
tasks = data;
}
});
,這給了相同的結果 - >空。
所以我明白了爲什麼甘特不會加載數據 - 任務變量中沒有數據。
有沒有人有一個運行的例子?
親切的問候
拉爾斯