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

How to reference specific record in dataSource

3 Answers 139 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 13 Apr 2012, 08:20 PM
I am reading a JSON file as a dataSource (example below), and binding that data to a ListView.

===== dataSource definition =====
var data = new kendo.data.DataSource({
transport: {
read: {
url: "json/data.json",
dataType: "json"
}
}
});

===== contents of data.json ===
[
{"id": "111", "location" : "Location A"},
{"id": "222", "location" : "Location B"}
.....
]

I would like to come back later and reference one of the elements in that datasource such as data[0].id, or data[0].location.

How do I go about exposing the data?

3 Answers, 1 is accepted

Sort by
0
Accepted
Sajid
Top achievements
Rank 1
answered on 17 Apr 2012, 06:41 AM
Hi mike,

 Solved the problem .

the Solution is 

dataSource.fetch(function(){
  console.log('Actually fetched');
  console.log(dataSource.data()[0].text);  
  alert(dataSource.data()[0].text);
 
});


you can alert or print Each index data with the corresponding  field .hope you  got 
0
Mike
Top achievements
Rank 1
answered on 17 Apr 2012, 01:51 PM
Can I run this code at any time, or is it dependent on having the data already loaded?  
0
Engifaar
Top achievements
Rank 1
answered on 31 May 2012, 04:56 AM
Define localDataSource. Then,

var items= localDataSource.data();
   for (var i = 0; i < items.length; i++) {
       alert(items [i].FirstName);
       alert(items [i].LastName);
   }
Tags
Data Source
Asked by
Mike
Top achievements
Rank 1
Answers by
Sajid
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Engifaar
Top achievements
Rank 1
Share this question
or