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

JSON Data Binding Problem

3 Answers 388 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Charlie
Top achievements
Rank 1
Charlie asked on 23 Jun 2012, 06:40 PM

Hi,

Just sampling your UI and it seems to be just what I am after. I have tried as the first project to use a combo box. Firstly I got the box working using your example on my site, now I am trying to bind a JSON data source to it.

the box initializes OK, but the values are filled with "undefined".

The code used to start the box is as follows:

<script type="text/javascript">
$(document).ready(function() {
    $("#titles").kendoComboBox({
        index: 0,
        dataTextField: "name",
        dataValueField: "value",
        filter: "q",
        dataSource: {
            type: "json",
            serverFiltering: true,
            serverPaging: true,
            pageSize: 20,
            transport: {
                read: "http://www.xxxxxxxxxx.net/kendo_getjson5.php"
            }
        }
    });
});
        
</script>

The data being returned by the script is as below. i am not sure what the top level element in the JSON should be>? I set it to dataSource? Maybe this is the problem?
Also my script accepts a query string with q= , so the filter should be set to q?

Also its not reading cross domain, its all on the same domain, so json is the correct type?

{"dataSource":[ {"value":"1366","name":"TAD1341GE "},{"value":"1367","name":"TAD1342GE "},{"value":"1368","name":"TAD1343GE "},{"value":"1369","name":"TAD1344GE "},{"value":"1370","name":"TAD1345GE "},{"value":"943","name":"TAD1640GE "},{"value":"944","name":"TAD1641GE "},{"value":"945","name":"TAD1642GE "},{"value":"1254","name":"TAD531GE "},{"value":"1255","name":"TAD532GE "}]}


Regards and TIA

Charlie

I have checked my datasournce with JSONLint to make sure its valid.

3 Answers, 1 is accepted

Sort by
0
Charlie
Top achievements
Rank 1
answered on 23 Jun 2012, 06:51 PM

I am half way there from spotting another forum reply. I removed the top level element in my JSON and set the content type within the PHP script to Content-Type: application/json;

It now loads the first fields. When I type however, it isn't updating with another call to the server on the q= variable I need?

I can set the name of this variable to something else if I need to, thats no problem.

How can I get it to update as I type?

NB The script is returning only 10 at the start, do i need it to return more?

Regards

Charlie

0
Henk Jelt
Top achievements
Rank 1
answered on 04 Jul 2012, 11:46 AM
Hi Charlie

I am far from an expert but from my browsing this forum I learnt that "type: json" should be "dataType: jsonp", and that this should be declared within the transport part.

maybe this helps?

Henk Jelt
0
James Shelton Agar
Top achievements
Rank 2
answered on 04 Jul 2012, 10:57 PM
as described in documentation http://www.kendoui.com/documentation/framework/datasource/overview.aspx 

according to your json structure, you probably need 
 schema: {
       
// the data which the data source will be bound to is in the "results" field
        data
: "datasource"
   
}

in your datasource definition
Tags
Data Source
Asked by
Charlie
Top achievements
Rank 1
Answers by
Charlie
Top achievements
Rank 1
Henk Jelt
Top achievements
Rank 1
James Shelton Agar
Top achievements
Rank 2
Share this question
or