Kendo 调度程序不会获取数据源
Kendo Scheduler Won't Take dataSource
我有一个 JSON 数组,看起来像这样:
var mockArr = [
{activity: "That One Activity", due_date: "07/22/2016", address: "22 Jump Ln", id: "42"},
{activity: "That Other Activity", due_date: "07/25/2015", address: "123 Fake St", id: "43"}
];
我正在尝试将其绑定到 kendo 调度程序小部件,其配置如下:
$("#scheduler").kendoScheduler({
date: new Date(),
height: 100,
views: [
{type: "day"},
{type: "month", selected: true},
{type: "agenda", selectedDateFormat: "{0:ddd, M/dd/yyyy} - {1:ddd, M/dd/yyyy}"}
],
mobile: "phone",
timezone: "Etc/UTC",
allDaySlot:true,
editable: false,
dataSource: {
data: mockArr,
schema: {
model: {
id: "taskId",
fields: {
taskId: { from: "id", type: "number" },
title: { from: "activity" },
start: { type: "date", from: "due_date" },
end: {type: "date", from: "due_date"},
description: { from: "address" }
}
}
}
}
});
当我 运行 网络小程序时,控制台输出 "TypeError: e is null",我得到 a page that looks like this
但是当我用静态 SchedulerEvent 替换 mockArr 和引用模型时,我得到了一个工作调度程序,例如:
var event = new kendo.data.SchedulerEvent({
id: 1,
title: "test event",
start: new Date("2016/7/22"),
end: new Date("2016/7/22")
});
为什么调度程序不喜欢我的数据源?
您遇到此问题的原因很少。
- 页面看起来像您提供的图片的原因是因为您指定了高度:100。删除此行kendo框架会自动处理它,您可以稍后根据需要指定它。
- 您的 Json 数组需要正确格式化。查看提供的代码中的代码段
- 数据源中的数据参数需要一个java脚本对象,您需要使用此数据解析它:JSON.parse(mockArr),
- 我注意到 kendo 不允许将字段中的 start/end 参数绑定到与您使用的 due_date 相同的名称,因此需要将其更改为
开始:{类型:"date",来自:"due_date"},
结束:{ 类型:"date",来自:"due_date1" },
除此之外你的代码工作正常我已经测试过了。
控制台错误 "web applet the console spits out "TypeError: e is null" 听起来特定于 java ,我假设您正在使用 java 并且这可能与 java 框架。
这是您的工作代码的实时版本。
导航到 Kendo UI online Editor 并删除预先填充的代码并粘贴下面提供的代码片段。
<!DOCTYPE html>
<html>
<head>
<base href="http://demos.telerik.com/kendo-ui/scheduler/index">
<style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
<title></title>
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.2.714/styles/kendo.common-material.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.2.714/styles/kendo.material.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.2.714/styles/kendo.default.mobile.min.css" />
<script src="//kendo.cdn.telerik.com/2016.2.714/js/jquery.min.js"></script>
<script src="//kendo.cdn.telerik.com/2016.2.714/js/kendo.all.min.js"></script>
<script src="//kendo.cdn.telerik.com/2016.2.714/js/kendo.timezones.min.js"></script>
</head>
<body>
<div id="example">
<div id="scheduler"></div>
</div>
<script>
var mockArr ='[{"activity":"That One Activity","due_date":"07/22/2016","due_date1":"07/22/2016","address":"22 Jump Ln","id":"42"},{"activity": "That Other Activity", "due_date": "07/25/2016","due_date1":"07/25/2016","address": "123 Fake St", "id": "43"}]';
$("#scheduler").kendoScheduler({
date: new Date(),
views: [
{type: "day"},
{type: "month", selected: true},
{type: "agenda", selectedDateFormat: "{0:ddd, M/dd/yyyy} - {1:ddd, M/dd/yyyy}"}
],
allDaySlot:true,
editable: true,
dataSource: {
data:JSON.parse(mockArr),
schema: {
model: {
id: "taskId",
fields: {
taskId: { from: "id", type: "number" },
title: { from: "activity" },
start: { type: "date", from: "due_date" },
end: { type: "date", from: "due_date1" },
description: { from: "address" }
}
}
}
}
});
</script>
</body>
</html>
我有一个 JSON 数组,看起来像这样:
var mockArr = [
{activity: "That One Activity", due_date: "07/22/2016", address: "22 Jump Ln", id: "42"},
{activity: "That Other Activity", due_date: "07/25/2015", address: "123 Fake St", id: "43"}
];
我正在尝试将其绑定到 kendo 调度程序小部件,其配置如下:
$("#scheduler").kendoScheduler({
date: new Date(),
height: 100,
views: [
{type: "day"},
{type: "month", selected: true},
{type: "agenda", selectedDateFormat: "{0:ddd, M/dd/yyyy} - {1:ddd, M/dd/yyyy}"}
],
mobile: "phone",
timezone: "Etc/UTC",
allDaySlot:true,
editable: false,
dataSource: {
data: mockArr,
schema: {
model: {
id: "taskId",
fields: {
taskId: { from: "id", type: "number" },
title: { from: "activity" },
start: { type: "date", from: "due_date" },
end: {type: "date", from: "due_date"},
description: { from: "address" }
}
}
}
}
});
当我 运行 网络小程序时,控制台输出 "TypeError: e is null",我得到 a page that looks like this
但是当我用静态 SchedulerEvent 替换 mockArr 和引用模型时,我得到了一个工作调度程序,例如:
var event = new kendo.data.SchedulerEvent({
id: 1,
title: "test event",
start: new Date("2016/7/22"),
end: new Date("2016/7/22")
});
为什么调度程序不喜欢我的数据源?
您遇到此问题的原因很少。
- 页面看起来像您提供的图片的原因是因为您指定了高度:100。删除此行kendo框架会自动处理它,您可以稍后根据需要指定它。
- 您的 Json 数组需要正确格式化。查看提供的代码中的代码段
- 数据源中的数据参数需要一个java脚本对象,您需要使用此数据解析它:JSON.parse(mockArr),
- 我注意到 kendo 不允许将字段中的 start/end 参数绑定到与您使用的 due_date 相同的名称,因此需要将其更改为
开始:{类型:"date",来自:"due_date"}, 结束:{ 类型:"date",来自:"due_date1" },
除此之外你的代码工作正常我已经测试过了。
控制台错误 "web applet the console spits out "TypeError: e is null" 听起来特定于 java ,我假设您正在使用 java 并且这可能与 java 框架。
这是您的工作代码的实时版本。
导航到 Kendo UI online Editor 并删除预先填充的代码并粘贴下面提供的代码片段。
<!DOCTYPE html>
<html>
<head>
<base href="http://demos.telerik.com/kendo-ui/scheduler/index">
<style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
<title></title>
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.2.714/styles/kendo.common-material.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.2.714/styles/kendo.material.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.2.714/styles/kendo.default.mobile.min.css" />
<script src="//kendo.cdn.telerik.com/2016.2.714/js/jquery.min.js"></script>
<script src="//kendo.cdn.telerik.com/2016.2.714/js/kendo.all.min.js"></script>
<script src="//kendo.cdn.telerik.com/2016.2.714/js/kendo.timezones.min.js"></script>
</head>
<body>
<div id="example">
<div id="scheduler"></div>
</div>
<script>
var mockArr ='[{"activity":"That One Activity","due_date":"07/22/2016","due_date1":"07/22/2016","address":"22 Jump Ln","id":"42"},{"activity": "That Other Activity", "due_date": "07/25/2016","due_date1":"07/25/2016","address": "123 Fake St", "id": "43"}]';
$("#scheduler").kendoScheduler({
date: new Date(),
views: [
{type: "day"},
{type: "month", selected: true},
{type: "agenda", selectedDateFormat: "{0:ddd, M/dd/yyyy} - {1:ddd, M/dd/yyyy}"}
],
allDaySlot:true,
editable: true,
dataSource: {
data:JSON.parse(mockArr),
schema: {
model: {
id: "taskId",
fields: {
taskId: { from: "id", type: "number" },
title: { from: "activity" },
start: { type: "date", from: "due_date" },
end: { type: "date", from: "due_date1" },
description: { from: "address" }
}
}
}
}
});
</script>
</body>
</html>