我的页面上有一个Kendo Scheduler。
<div kendo-scheduler k-options="schedulerOptions" k-data-source="items"></div>
我的角度控制器将调用服务器来获取数据,它看起来像这样,但我不知道我的URL参数在加载之前是什么($ scope。$ watch)。
$scope.$watch(function () { return MyService.leadID; }, function (newValue) {
if (newValue) {
getAppointmentsTabData(newValue);
}
});
var getAppointmentsTabData = function (leadID) {
MyService.getAppointmentsTabData(leadID)
.then(function (data) {
$scope.items = data;
}
}
);
};
如何将此数据绑定到我的Kendo Scheduler?
我可以使用此Scheduler来处理静态数据,但不能使用服务器发送时返回的JSON对象列表。我希望能够将我的$ scope.items绑定到dataSource,但这似乎不起作用。
这是schedulerOptions代码。
$scope.schedulerOptions = {
date: new Date("2014/10/13"),
startTime: new Date("2014/10/13 07:00 AM"),
height: 310,
views: [
"agenda",
{ type: "week", selected: true, allDaySlot: false },
{ selectedDateFormat: "{0:dd-MM-yyyy}" }
],
eventTemplate: "<span class='custom-event'>{{dataItem.title}}</span>",
allDayEventTemplate: "<div class='custom-all-day-event'>{{dataItem.title}}</div>",
timezone: "Etc/UTC",
dataSource: {
data: $scope.items,
schema: {
model: {
id: "id",
fields: {
id: { from: "ID", type: "number" },
appointmentId: { from: "AppointmentId", type: "number" },
resource: { from: "Resource", type: "number" },
description: { from: "Description" },
isAllDay: { type: "boolean", from: "IsAllDay" },
end: { from: "End", type: "date" },
start: { from: "Start", type: "date" },
title: { from: "Title", defaultValue: "No title" },
startTimezone: { from: "StartTimezone" },
endTimezone: { from: "EndTimezone" },
recurrenceRule: { from: "RecurrenceRule" },
recurrenceException: { from: "RecurrenceException" },
}
}
},
}
};
我可以让静态方法起作用。我不能真正使用看起来像这样的远程数据方法(下面)因为我不知道我的URL是什么,直到我的$ scope。$ watch被触发。我需要追加查询字符串参数。
dataSource: {
batch: true,
transport: {
read: {
url: "/MyController/GetMyData",
dataType: "json",
},
有没有人对如何动态填充我的Scheduler dataSource有任何建议?
我已经看到了这个问题Kendo update scheduler options dynamically,但是我没有运气得到setOptions()。如果我只能调用$ scope.myScheduler.setOptions(&#34; dataSource&#34;,myJsonObjectArry),那就太棒了,但什么都没有。
我能够操作$ scope.myScheduler._data(作为数组),但我需要某种形式的刷新方法来重绘我的UI。这种方法看起来并不合适。
感谢您的帮助。
答案 0 :(得分:4)
我正在回答我自己的问题。如果遇到这种情况,我就是这样解决的。
这是我的schedulerOptions现在。请注意,没有设置dataSource且没有架构。这是因为我将使用我自己的dataSource动态填充它。
$scope.schedulerOptions = {
date: new Date("2014/10/13"),
startTime: new Date("2014/10/13 07:00 AM"),
showWorkHours: true,
height: 310,
views: [
"agenda",
{ type: "week", selected: true, allDaySlot: false },
{ selectedDateFormat: "{0:dd-MM-yyyy}" }
],
edit: $scope.edit,
editable: {
template: $("#editor").html()
},
timezone: "Etc/UTC",
dataSource: {
data: [], // will be set dynamically
}
};
当我的数据返回到这个js控制器时,我会调用它。
$scope.myScheduler.dataSource.data(getSchedulerEvents($scope.data.items));
反过来会调用它,这会为我创建dataSource。
var getSchedulerEvents = function (items) {
var result = [];
var event;
for (var i = 0, length = items.length; i < length; i++) {
event = items[i];
result.push(new kendo.data.SchedulerEvent({
id: event.ID,
title: event.Title,
description: event.Description,
start: kendo.parseDate(event.Start),
end: kendo.parseDate(event.End),
isAllDay: event.IsAllDay,
recurrenceException: event.RecurrenceException,
recurrenceId: event.RecurrenceId,
recurrenceRule: event.RecurrenceRule,
resource: event.Resource,
}));
}
return result;
}
如果遇到这个问题,希望这有帮助。