0

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?

4

2 回答 2

3

您的代码有两个问题

  1. 首先你需要调用data.read() - 所以请求被执行
  2. 由于上述操作是异步操作,因此如果您在使用data.read()后立即调用它,则调用data.data()不会返回任何内容。要等到数据被检索到,您需要使用requestEnd事件。
于 2013-03-05T05:58:21.650 回答
-1

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)
于 2013-03-05T05:44:39.387 回答