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

Bind Json Object to LisiView

1 Answer 367 Views
ListView (Mobile)
This is a migrated thread and some comments may be shown as answers.
Hitesh
Top achievements
Rank 1
Hitesh asked on 14 May 2013, 06:23 AM
Hi,
I am retrieving  data from database into JSON object using $.ajax method. I want to bind that data to listview. I am using following example. but in following example json has read from the file but I don't .json file I've an object which I need to bind. Can anyone tell me how to bind json object.
<script type="text/javascript">
    var clientData = null;
    // Urls to access the WCF Rest service methods
    var GetClientUrl = "http://localhost:1000/Service/GetClients/agentId=AG9898";


    function initListView() {
        $.ajax({
            cache: false,
            type: "GET",
            async: false,
            dataType: "json",
            url: GetClientUrl,
            success: function (clients) {
                if (clients != null && clients != "undefined") {
                    clientData = clients.Clients;
                }
            },
            error: function (xhr) {
                clientData = null;
                alert(xhr.responseText);
            }
        });

        var ds = new kendo.data.DataSource({
            transport: {
                read: {
                    url: "team.json", //Here instead reading a data from file it should read from json object i.e. clientData
                    dataType: "json"
                }
            },
            change: function () {
                //debugger;
            }
        });
        $("#fixed-listview").kendoMobileListView({
            dataSource: ds,
            template: "#:SortName#"
        });
    }
</script>

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 15 May 2013, 12:58 PM
Hello Hitesh,

To bind the ListView to local data array please use data option.
$("#fixed-listview").kendoMobileListView({
    dataSource: { data: clientData },
    template: "#:SortName#"
});

I would like to remind you that the Ajax request is asynchronous. Please make sure that at the time when ListView is initialized, the clientData is already retrieved.

To avoid potential problems you can use a custom read transport.
Please check the 3rd code snippet called "Example - set read as a function".

Regards,
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
Hitesh
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or