2

我究竟做错了什么?我要做的就是从 API 获取一些数据并将其显示在屏幕上:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Kendo UI Test</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 type="text/javascript">
            $(document).ready(function()
            {
                var retrievedData = new kendo.data.dataSource({
                    transport: {
                        read: {
                            url: "http://puppygifs.tumblr.com/api/read/json",
                            dataType: "json"
                        }
                    }
                });

                $("#grid").kendoGrid({
                    dataSource: retrievedData,
                    pageSize: 10
                });
            });

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

错误发生在这部分:

var retrievedData = new kendo.data.dataSource({
                    transport: {
                        read: {
                            url: "http://puppygifs.tumblr.com/api/read/json",
                            dataType: "json"
                        }
                    }
                });

编辑:

我将如何修改代码以从如下所示的对象中捕获数据:

[
{
<NotificationNode>k__BackingField: {
isDirty: false,
isRecordAdded: false,
isRecordDeleted: false,
<CaseStatus>k__BackingField: null,
<CaseName>k__BackingField: null,
<CaseType>k__BackingField: null,
<CaseStage>k__BackingField: null,
<CaseNotificationId>k__BackingField: 0,
<CaseId>k__BackingField: 0,
<Comments>k__BackingField: null,
<WarningDays>k__BackingField: 0,
<NotificationDate>k__BackingField: "0001-01-01T00:00:00",
<LetterUrl>k__BackingField: null,
<NotificationId>k__BackingField: 0,
<NotificationDescription>k__BackingField: null,
<NotificationCount>k__BackingField: 1889,
<ParamValue1>k__BackingField: null,
<ParamValue2>k__BackingField: null,
<ParamValue3>k__BackingField: null,
<ParamValue4>k__BackingField: null,
<ParamValue5>k__BackingField: null,
<NotificationStatus>k__BackingField: 0,
<Checked>k__BackingField: false,
notificationTypeId: 1,
notificationType: "Add/Edit Gross Earnings",
actionPageName: null,
param1: null,
param2: null,
param3: null,
param4: null,
param5: null,
dateEntered: "0001-01-01T00:00:00",
whoEntered: 0,
dateChanged: "0001-01-01T00:00:00",
whoChanged: 0
},
<Notifications>k__BackingField: [ ],
<IsExpanded>k__BackingField: false
},
4

1 回答 1

1

您在 dataSource 选项上有错字,它必须是DataSource;您正在读取的数据来自另一个来源,因此您可以使用jsonpas dataType

提供的服务返回一组复杂的数据,您必须只读数据才能在网格中显示并绑定要在列中显示的数据。

您可以使用schemacolumns参数来执行此操作。

代码:

  $(document).ready(function () {
      var retrievedData = new kendo.data.DataSource({
          transport: {
              read: {
                  url: "http://puppygifs.tumblr.com/api/read/json",
                  dataType: "jsonp"
              }
          },
          schema: {
              data: "posts"
          }
      });
      $("#grid").kendoGrid({
          dataSource: retrievedData,
          columns: [{
              field: "id",
              title: "ID",
              width: 150
          }, {
              field: "url",
              title: "URL",
              width: 150
          }]
      });
  });

工作演示:jsFiddle

于 2013-07-25T17:45:56.437 回答