javascriptdhtmlx

Build object tasks for gantt.parse


The question is pretty trivial, but my level of programming doesn't allow me to solve it.

I'm trying to build an object, for display. Built it first with simple push method, then I realized there is an error and something is wrong.

Step by step, first I make ajax request to api server. I get data array, then I form object during enumeration. Example:

data = [];
$.ajax(settings).done(function (response) {
  obj = response.result.tasks;
  Object(obj).forEach(function (entry, index) {
    console.log(entry);
    startDatePlan = entry.startDatePlan.substring(0, 10);
    endDatePlan = entry.endDatePlan.substring(0, 10);
data.push ({id: entry.id, text:entry.title, start_date: startDatePlan, end_date: endDatePlan})    
  })
}); 

The output I get is an array like this:

[
    {
        "id": "7852",
        "text": "D#3628 7852",
        "start_date": "2021-10-21",
        "end_date": "2021-11-05"
    },
    {
        "id": "7854",
        "text": "D#3628 7854",
        "start_date": "2021-10-06",
        "end_date": "2021-10-21"
    },
    {
        "id": "7856",
        "text": "D#3628 7856",
        "start_date": "2021-09-28",
        "end_date": "2021-10-06"
    }
]

But this array doesn't work, having compared it to the demo version. I see that my properties are not defined as numbers and dates. But I can't figure out how to build the array correctly.

I even tried filling the object and pushing it into the array. But I faced with indices, which are not used in the demo.

gantt.parse({
    data:[
        {id:1, text:"Project #2", start_date:"01-04-2013", duration:18},
        {id:2, text:"Task #1",    start_date:"02-04-2013", duration:8,
            progress:0.6, parent:1},
        {id:3, text:"Task #2",    start_date:"11-04-2013", duration:8,
            progress:0.6, parent:1}
    ],
    links:[
        { id:1, source:1, target:2, type:1},
        { id:2, source:2, target:3, type:0}
  ]
});

Solution

  • Let's continue our discussion here:

    https://forum.dhtmlx.com/t/question-build-object-tasks-for-gantt-parse/73313