简体   繁体   中英

Simple Kendo UI remote DataSource returns empty

Here is a simple example I'm trying to build as an exercise and my DataSource object returns with no data.

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

        console.dir( data );

data.json

[
    {
        "text": "Brand One"
    },
    {
        "text": "Brand Two"
    },
    {
        "text": "Brand Three"
    },
    {
        "text": "Brand Four"
    }
]

Any ideas?

There are two issues with your code

  1. First you need to call data.read() - so the request is performed
  2. Since the operation above is an async one, invoking data.data() wont return anything if you call this immediately after using the data.read() . To wait until the data is retrieved you will need to use the requestEnd event.

I can load load array to datasource and returns object, see

var data_input= [
    {
        "text": "Brand One"
    },
    {
        "text": "Brand Two"
    },
    {
        "text": "Brand Three"
    },
    {
        "text": "Brand Four"
    }
];

var data = new kendo.data.DataSource({
            transport: {
                read: {
                    data: data_input,
                    dataType: "json"
                }
            }
        });

console.log(data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM