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

How to use DataSource (CRUD) on local JSON data

4 Answers 430 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Siddu
Top achievements
Rank 1
Siddu asked on 12 Jan 2013, 08:51 AM
 I am using DataSource for Kendo Template listview, but Unable to read data from list.json 


dataSource = new kendo.data.DataSource({
                    transport:{
                     read: lists.json
                        }
                });

         dataSource.read();
            var listView = $("#listView").kendoMobileListView({
                dataSource: dataSource,
                template: kendo.template($("#template").html()),
                
            });

and
list.json:
[
{"name":"Customer0","address1":"0 Winding River Lane"},
{"name":"Customer1","address1":"1 Winding River Lane"},
{"name":"Customer10","address1":"10 Winding River Lane"},
{"name":"Customer100","address1":"100 Winding River Lane"}
]


guide me to know the problem.. thanks in advance.

4 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 15 Jan 2013, 09:17 AM
Hello Siddu,

If I understood correctly you would like to read the data from a local JSON file, which is different from using local data (JavaScript array).

In that case you should specify the JSON file path as a URL of the read transport. If we assume that the lists.json file is located at the same folder as your index page, the configuration should look like the following:
<div id="home" data-role="view">
    <ul id="list" data-role="listview" data-source="dataSource" data-template="tmp"></ul>
</div>
<script id="tmp" type="text/x-kendo-template">
    #: name # || #: address1 #
</script>
<script>
    var app = new kendo.mobile.Application();
     
    var dataSource = new kendo.data.DataSource({
        transport:{
            read: "lists.json"
        }
    });
</script>

I hope this will help.

Kind 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!
0
Siddu
Top achievements
Rank 1
answered on 18 Jan 2013, 09:28 AM
Thank for reply Alexander. it's working as a charm.

But I have got another issue i.e would like to update or delete on Mobile ListView.

should I use kendo.model and schema for this issue? 




0
Accepted
Alexander Valchev
Telerik team
answered on 21 Jan 2013, 01:52 PM
Hi Siddu,

To achieve this you should use the DataSource API methods. Also each record should have unique ID field which is defined in the DataSource's model.
Please check this sample project - it demonstrates how to implement create/delete operations with mobile ListView, DataSource and MVVM.

Kind 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!
0
Siddu
Top achievements
Rank 1
answered on 22 Jan 2013, 05:20 AM
Thank You Alexander, Sample Project works pretty good. Need to work more on it.

Once again Thanks for quick reply.
Tags
Data Source
Asked by
Siddu
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Siddu
Top achievements
Rank 1
Share this question
or