【发布时间】:2023-04-04 08:07:01
【问题描述】:
尝试在 kendo schedular 的自定义视图中连接多选,但它没有显示数据源数据。数据来自服务器并存储在资源中。其他字段显示正常。有人可以帮我解决这个问题吗?
数据源
$scope.attendeesDS = new kendo.data.DataSource({
type: "odata",
transport: {
read:
{
url: "odata/AttendeesOData",
dataType: "json"
}
},
schema: {
data: function(data) {
return data["value"];
},
total: function(data) {
return data["odata.count"];
},
model: {
fields: {
value: { from: "Id", type: "number" },
text: { from: "text", type: "string" },
color: { from: "color", type: "string" }
}
}
},
serverPaging: true,
serverSorting: true,
serverFiltering: true,
pageSize: 15
});
调度器初始化
$("#ksheduler").kendoScheduler({
date: new Date(),
startTime: new Date("2015/1/1 07:00 AM"),
dateHeaderTemplate: kendo.template("<strong>#=kendo.toString(date, 'd/M')#</strong>"),
height: 600,
views: [
"day",
{ type: "workWeek", selected: true },
"week",
"month",
"agenda",
{ type: "timeline", eventHeight: 50 }
],
timezone: "Etc/UTC",
editable: {
template: kendo.template($("#schedulerTemplate").html())
},
dataSource: {
type: "odata-v4",
batch: false,
sync: function (e) {
var scheduler = $("#ksheduler").data("kendoScheduler");
if (scheduler) {
scheduler.refresh();
scheduler.dataSource.read();
}
},
transport: {
//cache: false,
read: {
url: "odata/ScheduleOData",
dataType: "json",
contentType: "application/json; charset=utf-8",
},
update: {
url: "odata/ScheduleOData",
type: "Post",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: function (response) {
if (response.Attendees == null) {
response.Attendees = [];
}
if (response.Clients == null) {
response.Clients = [];
}
if (response.Tutees == null) {
response.Tutees = [];
}
if (response.Placements == null) {
response.Placements = [];
}
return response;
},
},
create: {
url: "odata/ScheduleOData",
type: "Post",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: function (response) {
if (response.Attendees == null) {
response.Attendees = [];
}
if (response.Clients == null) {
response.Clients = [];
}
if (response.Tutees == null) {
response.Tutees = [];
}
if (response.Placements == null) {
response.Placements = [];
}
return response;
},
},
destroy: {
url: function (data) {
return "odata/ScheduleOData(" + data.Id + ")";
},
type: "Delete",
dataType: "json",
contentType: "application/json; charset=utf-8",
},
parameterMap: function (data, operation) {
if (operation == "destroy") {
return;// kendo.stringify(data);
}
var d = kendo.data.transports.odata.parameterMap(data, operation);
delete d.$inlinecount; // <-- remove inlinecount parameter
delete d.$callback;
return d;
}
},
schema: {
data: function (data) {
return data["value"];
},
total: function (data) {
return data['@odata.count'];
},
model: {
id: "taskId",
fields: {
taskId: { from: "Id", type: "number" },
title: { from: "Title", defaultValue: "Interview", validation: { required: true } },
start: { type: "date", from: "StartDate" },
end: { type: "date", from: "EndDate" },
startTimezone: { from: "StartTimezone" },
endTimezone: { from: "EndTimezone" },
description: { from: "Description" },
recurrenceId: { from: "RecurrenceID", defaultValue: 0 },
recurrenceRule: { from: "RecurrenceRule" },
recurrenceException: { from: "RecurrenceException" },
isAllDay: { type: "boolean", from: "IsAllDay" },
isInterview: { type: "boolean", from: "IsInterview", title: "Interview", defaultValue: true },
isSession: { type: "boolean", from: "IsSession", title: "Session" },
attendees: { from: "Attendees", nullable: true },
clients: { from: "Clients", nullable: true },
tutees: { from: "Tutees", nullable: true },
placements: { from: "Placements", nullable: true },
ownerId: { from: "OwnerID", defaultValue: 0 },
location: { from: "Location" },
notes: { from: "Notes" },
}
}
},
},
resources: [
{
field: "attendees",
dataSource: $scope.attendeesDS,
multiple: true,
dataTextField: "text",
dataValueField: "id",
title: "Tutors",
nullable: true
}
]
});
自定义模板内的多选
<div class="k-edit-label">
<label for="Attendees">Tutors</label>
</div>
<div data-container-for="Attendees" class="k-edit-field">
<select id="Attendees" multiple="multiple" name="Attendees"
data-role="multiselect"
data-bind="value: attendees"
data-source="attendees"
data-text-field="text"
data-value-field="id"
data-value-primitive="true"></select>
</div>
【问题讨论】: