无法填充Kendo Scheduler

本文关键字:Scheduler Kendo 填充 | 更新日期: 2023-09-27 18:26:39

我正在尝试在我的网站中实现新的剑道调度器。我可能只是错过了什么,但我无法让时间表显示约会。这是我的看法

@model OpenRoad.Web.Areas.Team.Models.AppointmentListModel
@using Combres.Mvc
@{
    ViewBag.Title = "Calendar";
    Layout = "~/Views/Shared/_LayoutSingleColumn.cshtml";
}
@section scripts {
   <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")"> </script>
    <script src="@Url.Content("~/Scripts/kendo/kendo.all.min.js")"></script>
    <script>
        $(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: "jsonp"
                        },
                        update: {
                            url: "/Team/Calendar/UpdateAppointment",
                            dataType: "jsonp"
                        },
                        create: {
                            url: "/Team/Calendar/Index",
                            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: "TaskID", type: "number" },
                                title: { from: "Title", defaultValue: "No title", validation: { required: true } },
                                start: { type: "date", from: "Start" },
                                end: { type: "date", from: "End" },
                                startTimezone: { from: "StartTimezone" },
                                endTimezone: { from: "EndTimezone" },
                                description: { from: "Description" },
                                recurrenceId: { from: "RecurrenceID" },
                                recurrenceRule: { from: "RecurrenceRule" },
                                recurrenceException: { from: "RecurrenceException" },
                                ownerId: { from: "OwnerID", defaultValue: 1 },
                                isAllDay: { type: "boolean", from: "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" }
                        ]
                    }
                ]
            });
            $("#people :checkbox").change(function (e) {
                var checked = $.map($("#people :checked"), function (checkbox) {
                    return parseInt($(checkbox).val());
                });
                var filter = {
                    logic: "or",
                    filters: $.map(checked, function (value) {
                        return {
                            operator: "eq",
                            field: "ownerId",
                            value: value
                        };
                    })
                };
                var scheduler = $("#scheduler").data("kendoScheduler");
                scheduler.dataSource.filter(filter);
            });
        });
</script>
    }
@section styles{
     <link href="@Url.Content("~/Content/kendo/kendo.common.min.css")" rel="stylesheet" />
    <link href="@Url.Content("~/Content/kendo/kendo.default.min.css")" rel="stylesheet" />
    }

    <div id="example" class="k-content">
    <div id="scheduler"></div>
</div>

这是我使用的型号

 public class AppointmentListModel
    {
        public int TotalItemCount { get; set; }
        public PagedList<Appointment> ListItems { get; set; }
        public List<Calendar> CalendarItems { get; set; }
    }
  public class Calendar
    {
        public int TaskId { get; set; }
        public int UserId { get; set; }
        public string Title { get; set; }
        [DisplayFormat(ConvertEmptyStringToNull = false)]
        public string Description { get; set; }
        [DisplayFormat(ConvertEmptyStringToNull = false)]
        public string StartTimezone { get; set; }
        public DateTime Start { get; set; }
        public DateTime End { get; set; }
        [DisplayFormat(ConvertEmptyStringToNull = false)]
        public string EndTimezone { get; set; }
        [DisplayFormat(ConvertEmptyStringToNull = false)]
        public string RecurranceRule { get; set; }
        public int? RecurranceId { get; set; }
        [DisplayFormat(ConvertEmptyStringToNull = false)]
        public string RecurranceException { get; set; }
        public bool IsAllDay { get; set; }
    }

这是我用来设置读取数据源的函数

public ActionResult PopulateCalendar()
        {
            using (var entities = new OpenRoad.Data.Repository.OpenRoadEntities())
            {
                var model = new Models.AppointmentListModel();
                var appointments = (from e in entities.Appointments
                                    where e.UserId == OpenRoad.Web.Session.UserId
                                    select new Models.Calendar
                                    {
                                        TaskId = e.AppointmentId,
                                        UserId = e.UserId ?? '1',
                                        Title = e.Subject,
                                        Start = e.StartTimeUtc ?? DateTime.Now,
                                        End = e.EndTimeUtc ?? DateTime.Now,
                                        IsAllDay = false
                                    }).OrderBy(o => o.Start);
                model.CalendarItems = new List<Models.Calendar>(appointments);
                return Json(model, JsonRequestBehavior.AllowGet);
            }
        }
    }

如果有人能帮上忙,我将不胜感激。

无法填充Kendo Scheduler

您必须绑定当前请求上的事件。将参数[DataSourceRequest]DataSourceRequest请求添加到方法中,并在最后将其绑定到请求。参见以下内容:

public ActionResult PopulateCalendar()
{
  // Add code
  return this.Json(model.ToDataSourceResult(request));
}

您必须导入Kendo.Mvc.Extensions;

您正在将dataSource设置为使用JSONP,但在操作中您只是返回JSON

JSONP接受一个标准的JSON响应并封装在一个函数调用中。这允许通过在HTML文档中添加<script>标签来加载它

JSON示例{ 'hello': 'world', 'num': 7 }

JSONP示例callback({ 'hello': 'world', 'num': 7 });

MVC没有对JSONP的内置支持,所以你可以在中(看看这个),或者看起来你在同一个域上使用它,所以纯JSON可以在中工作