This is a migrated thread and some comments may be shown as answers.

Mapping nested / complex data to the model

1 Answer 384 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 25 Sep 2015, 02:29 PM

We're talking to an existing web service that is returning the data in a JSON format along these lines (excuse any format typos as this is mocked data):

{
  "SelectedLocationID": 123,
  "SelectedPeriodID": 234,
  "DOBShifts": {
    "Monday 9/21/2015": [
      {
        "ResultID": 1,
        "DOB": "9/21/2015",
        "JobID": 1,
        "JobName": "Job 1",
        "StartTime": "9/21/2015 12:00:00 PM",
        "EndTime": "9/21/2015 4:00:00 PM",
        "EmployeeName": "employee 1",
        "EmployeeID": 1
        "Color": "      "
      },
      {
        "ResultID": 2,
        "DOB": "9/21/2015",
        "JobID": 1,
        "JobName": "Job 1",
        "StartTime": "9/21/2015 1:00:00 PM",
        "EndTime": "9/21/2015 5:00:00 PM",
        "EmployeeName": "employee 2",
        "EmployeeID": 2,
        "Color": "      "
      }
    ],
    "Tuesday 9/22/2015": [
...
    ]
  }
}

 

Is there a way to bind the model fields to this nested JSON data, especially with the data stamps that will vary inside the DOBShifts node?  Something like

taskId: { from: "DOBShifts.(formatteddate?).ResultID", type: "number" }

 

Or would a better approach be to pull this data into a separate function, format it in a simpler object, then map that datasource?

 

Thanks.

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 29 Sep 2015, 02:52 PM
Hello Bob,

If you would like to bind the widget to a specific DOBShifts timestamp (for instance "Monday 9/21/2015"), then you will need to define the datasource scheme.data option correctly and then specify the correct from values for all Model fields. Refer to our online demos for more details how the from field is defined.

If you would like to show all shifts, then you will need to combine the timestamp arrays and return a single one. You can do that in schema.data callback if you want.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Scheduler
Asked by
Bob
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or