我做错了什么?我想要做的就是从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
},
答案 0 :(得分:1)
您有关于dataSource选项的拼写错误,它必须是DataSource
;您正在阅读的数据来自其他来源,因此您可以将jsonp
用作dataType
。
提供的服务返回一组复杂的数据,您必须只读取数据以在网格中显示,并绑定要在列中显示的数据。
代码:
$(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
}]
});
});