1

我正在尝试在我的网站中实施新的剑道调度程序。我可能只是错过了一些东西,但我无法让调度程序显示约会。这是我的看法

@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);
            }

        }
    }

如果有人可以提供帮助,我将非常感激。

4

2 回答 2

1

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

public ActionResult PopulateCalendar()
{
  // Add code

  return this.Json(model.ToDataSourceResult(request));
}

您必须导入 Kendo.Mvc.Extensions;

于 2013-09-18T12:39:56.423 回答
0

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

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

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

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

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

于 2013-08-05T18:37:54.810 回答