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

ListView dataSource error

1 Answer 139 Views
ListView (Mobile)
This is a migrated thread and some comments may be shown as answers.
Tyler
Top achievements
Rank 1
Tyler asked on 24 Mar 2012, 12:50 PM
Hi everyone,
I'm trying to put JSON object received by an AJAX Call, but i don't really know how to use it properly, when i try to convert it into an Object or trying to use it with no modification i don't get anything on the web page.

Here is my JSON message : 
[{"id":"3","views":"0","title":"Video1","description":"Video1.mp4","created_at":"2012-03-21 00:00:00","updated_at":"2012-03-21 00:00:00","link":"\/videos\/Video1.mp4","add_by":"1","category":"1","convert":"0","group_fkid":"1"},{"id":"2","views":"0","title":"Video2","description":"Video2.mp4","created_at":"2012-03-21 00:00:00","updated_at":"2012-03-21 00:00:00","link":"\/videos\/Video2.mp4","add_by":"1","category":"1","convert":"0","group_fkid":"1"},{"id":"1","views":"0","title":"Video3","description":"Video3.mp4","created_at":"2012-03-21 10:00:00","updated_at":"2012-03-21 10:00:00","link":"\/upload\/videos\/Video3.mp4","add_by":"1","category":"1","convert":"0","group_fkid":"1"},{"id":"4","views":"0","title":"Video de test","description":"31.mp4","created_at":"2012-03-21 00:00:00","updated_at":"2012-03-21 00:00:00","link":"\/upload\/videos\/31.mp4","add_by":"1","category":"1","convert":"0","group_fkid":"1"}]

Can someone explain me the right way to use it with no error ?

Thanks,
Tyler

1 Answer, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 26 Mar 2012, 09:07 AM
Hi Tyler,

I suggest to configure the dataSource component in order bind the ListView to remote data. Please check the corresponding documentation and review in details the transport and schema objects. Fist one is responsible for loading of the data via Ajax calls, while the second one is used to define the raw data format. For example:
var dataSource = new kendo.data.DataSource({
    transport: {
        read: {
            url: <your url >,
            dataType: "json"
        }
    },
    schema: {
        model: {
            fields: {
                id: { type: "number" },
                title: { type: "string" },
                description: { type: "string" },
                updated_at: { type: "date" },
                < describe rest of the fields >
            }
        }
    }
}

Once you have got the configured dataSource, you could pass it to the ListView widget as shown in the source code of this example.


All the best,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
ListView (Mobile)
Asked by
Tyler
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or