简体   繁体   English

简单的Kendo UI远程DataSource返回空

[英]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. 这是一个简单的例子,我正在尝试构建一个练习,我的DataSource对象返回时没有数据。

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

        console.dir( data );

data.json 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 首先,您需要调用data.read() - 以便执行请求
  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() . 由于上面的操作是异步操作,因此如果在使用data.read()之后立即调用data.data(),则不会返回任何内容。 To wait until the data is retrieved you will need to use the requestEnd event. 要等到检索数据,您需要使用requestEnd事件。

I can load load array to datasource and returns object, see 我可以将load数组加载到datasource并返回对象,参见

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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