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

Using the DataSource to read a single packet, non-array JSON data

2 Answers 107 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 04 May 2012, 03:06 PM
I have a URL link to a single packet non-array JSONP data.  I am having trouble configuring the Kendo DataSource to read it correctly.  I know it has something to do with the schema, but I am not finding a lot of documentation on the configuration parameters.  My JSON data looks like this:

{"results":{"data1":0.928287,"data2":0.966691,"data3":0.897367,"adataA":0.329710,"adataB":0.818630,"adataC":0.667666,"adataIA":0.983468,"adataIB":0.726931,"adataIC":0.848747,"active":0.616980,"active1":0.616980,"factor":0.553658,"efficiency":1.454451,"system":true,"alarm":true,"connect":false,"state":21.815668,"online":true},"timeoday":"5/4/20127:50 AM"}

I have verified that the JSON data is valid using JSONLint.  I have created a simple test HTML file to read this data from the service which looks like this:

<!DOCTYPE html>
<html>
<head>
    <title>datasource test</title>
    <script src="../../../js/jquery.min.js"></script>
<script src="../../../js/kendo.data.min.js"></script>
<script src="../../../js/kendo.dataviz.min.js"></script>

</head>
<body>  
        <div id="example">
            <script>
var dataSource = new kendo.data.DataSource({
transport: {
read: {
//url: "http://search.twitter.com/search.json?q=HTML5",
url: "http://localhost:8080/APEI_Snap/APEI_Data_Snapshot/1",
dataType: "jsonp",
type: "GET"
}
},
schema: {
data: "results"
},
change: function() {
var view = this.view();
alert(kendo.stringify(view[0]));  //I know view[0] is wrong since I don't have an array....
}
});
dataSource.read();
            </script>
        </div>
</body>
</html>

I need to be able to pulls out the individual data points, which I will eventually bind to the dataviz objects.  Can someone help me figure out how to setup the datasource?  Thanks for any help you can provide.

Mark

2 Answers, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 2
answered on 24 May 2012, 02:45 AM
Did you manage to get this working? I have the exact same scenario.

When dataSource.read() is called, I know that the request is issued and that a result is returned (I can see this from the debug window in Chrome), but neither the change nor the error events are fired.

Any idea?

Alex
0
Alex
Top achievements
Rank 2
answered on 24 May 2012, 04:25 AM
I don't know if there is another method, but this code works for this purpose:

$.post("serviceurl", function (data) {
  alert(data);
});

In my code I use data directly as a viewmodel to bind to my view.

Alexis
Tags
Data Source
Asked by
Mark
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 2
Share this question
or