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

[Solved] how to read data from dataSource transport

1 Answer 154 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 18 Nov 2014, 03:28 AM
My API is returning the following JSON:

{
  "data": [
      {
      "BookingID": 1,
      "Driver": "John Doe",
      "VehicleID": 1,
      "Registration": "CHH708",
      "Fleet": "DN30",
      "Destination": "Akaroa",
      "Notes": "Going to ...",
      "StartTimezone": null,
      "Start": "2014/11/20 08:00",
      "End": "2014/11/20 11:00",
      "EndTimezone": null,
      "RecurrenceRule": null,
      "RecurrenceID": null,
      "RecurrenceException": null,
      "Pickup": false
      },
      {
      "BookingID": 2,
      "Driver": "Paul McCartney",
      "VehicleID": 2,
      "Registration": "DRF457",
      "Fleet": "DN30",
      "Destination": "Whangarei",
      "Notes": "Going to ...",
      "StartTimezone": null,
      "Start": "2014/11/19 14:00",
      "End": "2014/11/19 19:00",
      "EndTimezone": null,
      "RecurrenceRule": null,
      "RecurrenceID": null,
      "RecurrenceException": null,
      "Pickup": true
      }
  ],
  "success": true,
  "status": 200
}

how do I specidy in my model that what I'm after is inside "data" ?
I have the following:
dataSource: {
                            transport: {
                                read: {
                                    url: "http://mocksvc.mulesoft.com/mocks/9c484836-5464-4c75-b8e5-1f433e861bd1/bookings",
                                    dataType: "jsonp"
                                }
                             },
                            schema: {
                                model: {
                                    fields: {
                                        bookingId: { from: "BookingID", type: "number" },
                                        destination: { from: "Destination", type: "string" },
                                        registration: { from: "Registration", type: "string" },
                                        fleet: { from: "Fleet", type: "string" },
                                        driver: { from: "Driver", type: "string" },
                                        start: { type: "date", from: "Start" },
                                        end: { type: "date", from: "End" },
                                        bookedDateTime: { type: "date", from: "BookedDateTime" },
                                        pickupDateTime: { type: "date", from: "PickUpTime" },
                                        dropoffDateTime: { type: "date", from: "DropOffTime" },
                                        notes: { from: "Notes" },
                                        vehicleId: { from: "VehicleID"},
                                        pickup: { type: "boolean", from: "Pickup" },
                                        dropoff: { type: "boolean", from: "DropOff" },
                                        actions: { from: "BookingID", type: "number" }
                                    }
                                }
                            },

but it's not reading it...

1 Answer, 1 is accepted

Sort by
0
Ben
Top achievements
Rank 1
answered on 19 Nov 2014, 02:43 AM
I got it working by using angular scope and $resource instead
Tags
Data Source
Asked by
Ben
Top achievements
Rank 1
Answers by
Ben
Top achievements
Rank 1
Share this question
or