0
有沒有方法可以在頁面加載上設置模型值。因爲我需要它用模型值填充模式。我嘗試了一個document.ready ajax調用來獲取模型,但它告訴我,模型在ajax調用發生之前沒有任何價值。在頁面加載時設置模型值
這裏是代碼,你可以看到IM如何試圖填充架構,但它不會打功能
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")"> </script>
<script src="@Url.Content("~/Scripts/kendo/kendo.all.min.js")"></script>
<script>
$(document).ready(function() {
$.ajax({
url: '/Team/Calendar/PopulateCalendar/',
type: "POST",
data: $(this).serialize(),
});
});
$(function() {
$("#scheduler").kendoScheduler({
date: new Date("2013/6/13"),
startTime: new Date("2013/6/13 07:00 AM"),
height: 600,
views: [
"day",
{ type: "week", selected: true },
"month",
"agenda"
],
timezone: "Etc/UTC",
dataSource: {
batch: true,
transport: {
read: {
url: "/Team/Calendar/PopulateCalendar/",
dataType: "json"
},
update: {
url: "http://demos.kendoui.com/service/tasks/update",
dataType: "jsonp"
},
create: {
url: "http://demos.kendoui.com/service/tasks/create",
dataType: "jsonp"
},
destroy: {
url: "http://demos.kendoui.com/service/tasks/destroy",
dataType: "jsonp"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
schema: {
model: {
id: "taskId",
fields: {
taskId: { from: "@Model.CalendarItems.Select(calendar=> calendar.TaskId)", type: "number" },
title: { from: "@Model.CalendarItems.Select(calendar=> calendar.Title)", defaultValue: "No title", validation: { required: true } },
start: { type: "date", from: "@Model.CalendarItems.Select(calendar => calendar.Start)" },
end: { type: "date", from: "@Model.CalendarItems.Select(calendar => calendar.End)" },
startTimezone: { from: "@Model.CalendarItems.Select(calendar => calendar.StartTimezone)" },
endTimezone: { from: "@Model.CalendarItems.Select(calendar => calendar.EndTimezone)" },
description: { from: "@Model.CalendarItems.Select(calendar => calendar.Description)" },
recurrenceId: { from: "@Model.CalendarItems.Select(calendar => calendar.RecurrenceId)" },
recurrenceRule: { from: "@Model.CalendarItems.Select(calendar => calendar.RecurrenceRule)" },
recurrenceException: { from: "@Model.CalendarItems.Select(calendar => calendar.RecurrenceException)" },
ownerId: { from: "OwnerID", defaultValue: 1 },
isAllDay: { type: "boolean", from: "@Model.CalendarItems.Select(calendar => calendar.IsAllDay)" }
}
}
},
filter: {
logic: "or",
filters: [
{ field: "ownerId", operator: "eq", value: 1 },
{ field: "ownerId", operator: "eq", value: 2 }
]
}
},
resources: [
{
field: "ownerId",
title: "Owner",
dataSource: [
{ text: "Alex", value: 1, color: "#f8a398" },
{ text: "Bob", value: 2, color: "#51a0ed" },
{ text: "Charlie", value: 3, color: "#56ca85" }
]
}
]
});
在'.Select(...)'之後添加'.First()','.Single()'或'.FirstOrDefault()'。目前,您正在獲取值列表而不是單個值。 –
第二:看看你生成的HTML。它也應該提供線索。如果可能的話,在這裏發佈一些重要的部分。 –