Resource datasource from JSON

3 posts, 0 answers
  1. Andrew
    Andrew avatar
    2 posts
    Member since:
    Feb 2015

    Posted 09 Mar 2015 Link to this post

    I've got a api endpoint that spits out the following JSON:

    [{"Start": "2015-03-08T21:43:31Z", "Attendee": ["andrew", "bobo"], "End": "2015-03-08T22:43:33Z", "Description": "", "TaskID": 1, "Title": "Test Event", "OwnerID": 2, "IsAllDay": false}]

                schema: {
                    model: {
                        id: "taskId",
                        fields: {
                            taskId: { from: "TaskID", type: "number" },
                            title: { from: "Title", defaultValue: "No title", validation: { required: true } },
                            start: { type: "date", from: "Start" },
                            end: { type: "date", from: "End" },
                            ownerId: { from: "OwnerID", defaultValue: 1 },
                            attendee: { from: "Attendee"},
                            isAllDay: { type: "boolean", from: "IsAllDay" }
                        }
                    }
            },

            resources: [
                {
                    field: "attendee",
                    title: "Attendee",
                    dataSource: [
                        { text: "Alex", value: 1, color: "#f8a398" },
                        { text: "Bob", value: 2, color: "#51a0ed" },
                        { text: "Charlie", value: 3, color: "#56ca85" }
                    ]
                }
            ]
         },


    All the examples I've seen for custom resources are not derived but are hard coded.  How do I get the values JSON into the dataSource resource for attendee?













  2. Andrew
    Andrew avatar
    2 posts
    Member since:
    Feb 2015

    Posted 09 Mar 2015 in reply to Andrew Link to this post

    Is this how you have to do it?  Create a separate data source resource just to get the list of attendees?  This works, but it seems verbose.

            resources: [
                {
                    field: "Attendee",
                    title: "Attendee",
                    dataSource: {
                transport: {
                   read: {
                       url: "/scheduler/getattendees/",
                       dataType: "json"
                   },
                    },
                    schema: {
                model:{
                id: "ID",
                fields: {
                text: {from: "Attendee"}
                }
                }
                }
                },
                }
            ]
  3. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 11 Mar 2015 Link to this post

    Hi Andrew,

    You are correct - if you need to load the resource items from remote source you should set it's "dataSource" option. In this case it's not required to define the "schema" option (you can leave only the transport) of the dataSource as the data would be read-only on the client side. 

    Regards,
    Vladimir Iliev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top