简单的Json连接无法正常工作 [英] Simple Json connection not working

查看:119
本文介绍了简单的Json连接无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使自己熟悉kendo ui数据源,我从未使用过JSON,并已使用您的文档构建了以下内容:

I am trying to familiarise myself with the kendo ui dataSource, I have never before used JSON and have constructed the following using your documentation:

HTML:

<!doctype html>
<html>
    <head>
        <title>Kendo UI Web</title>
        <link href="styles/kendo.common.min.css" rel="stylesheet" />
        <link href="styles/kendo.default.min.css" rel="stylesheet" />
        <script src="js/jquery.min.js"></script>
        <script src="js/kendo.web.min.js"></script>
    </head>
    <body>
        <div id="grid"></div>
        <script>
        $(document).ready(function () {
            var myDataSource = new kendo.data.DataSource({
                transport: {
                    read: {
                        url: "people.json",
                        dataType: "json"
                    }
                }
            });

            $("#grid").kendoGrid({
                dataSource: myDataSource,
                    columns: [
                    {
                        field: "firstName",
                        title: "First Name"
                    },
                    {
                        field: "lastName",
                        title: "Last Name"
                }]
            });

        });

    </script>
    </body>
</html>

Json文件:

{
    "people": [
        { "firstName":"John" , "lastName":"Doe" },
        { "firstName":"Anna" , "lastName":"Smith" },
        { "firstName":"Peter" , "lastName":"Jones" }
    ]
}

网格不加载任何数据,我只看到标题.

The grid doesn't load any data, all I see are the headers.

我仅使用HTML和JSON文件尝试过此操作,也曾在Visual Studio中尝试过此操作.

I have tried this using simply HTML and a JSON file, I have also tried this in Visual Studio.

任何帮助将不胜感激

推荐答案

在您的JSON中,传输的数据不是array而是object,因此您需要指定数据在该对象中的存储位置,从而有可能到KendoUI数据源找到它.使用 schema.data

In your JSON the data transmitted is not an array but an object so you need to specify where in that object the data is stored, making possible to KendoUI DataSource finding it. This is specified using schema.data

您的数据源应为:

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

这篇关于简单的Json连接无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆