Kendo-UI Scheduler' GetTimezoneOffset'错误

时间:2017-01-29 05:51:25

标签: javascript json salesforce crud kendo-scheduler

要开始使用Kendo UI在日历上工作,我首先要从Salesforce组织中提取事件并在计划中显示它们。但是,我一直受到"无法读取财产' getTimezoneOffset'未定义的错误,我正在寻求帮助。我的JS是:

var data = '{!jsonString}';
       var scheduler = $('#scheduler').kendoScheduler({
       date: new Date(),
       startTime: new Date(),
       height: 700,
       timezone: "Etc/UTC",
       views: [
          {type: "week", selected: true},
          "week",
          "month",
          "agenda"
       ],
       dataSource: {
          batch: true,
          transport: {
              read: function(e){
                  console.log(data);
                  e.success(data);
              },
              update: {
                  url: "http://demos.telerik.com/kendo-ui/service/tasks/update",
                  dataType: "jsonp"
              },
              create: {
                  url: "http://demos.telerik.com/kendo-ui/service/tasks/create",
                  dataType: "jsonp"
              },
              destroy: {
                  url: "http://demos.telerik.com/kendo-ui/service/tasks/destroy",
                  dataType: "jsonp"
              },
              parameterMap: function(options, operation) {
                  if (operation !== "read" && options.models) {
                      return {models: kendo.stringify(options.models)};
                  }
              }
          },
          schema: {
              model: {
                  id: "OwnerId",
                  fields: {
                       taskId: { from: "TaskID" },
                       title: { from: "Title", defaultValue: "No title", validation: { required: true } },
                       start: { type: "date", from: "Start" },
                       end: { type: "date", from: "EndTime" },
                       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" }
                  }
              }
          }
      }
                        //});
  });

数据变量是JSON格式:

  

[{"名称":"满足""的TaskID":" 00U410000059ZjbEAE"" StartTimezone&#34 ;: "其他/ UTC""开始":" 2017年1月26日&#34 ;,   " RecurrenceRule":null," RecurrenceId":null,   " RecurrenceException":null," OwnerId":" 005410000020eLnAAI",   " IsAllDay":false," EndTimezone":" Etc / UTC"," End":" 2017-01-26&# 34 ;,   "说明":"会议"},{"标题":"会议",   " TaskId":" 00U410000059ZjcEAE"," StartTimezone":" Etc / UTC",   "开始":" 2017-01-26"," RecurrenceRule":null," RecurrenceId":null,   " RecurrenceException":null," OwnerId":" 005410000020eU9AAI",   " IsAllDay":false," EndTimezone":" Etc / UTC"," End":" 2017-01-26&# 34 ;,   "说明":"会议"}等...}]

根据read.log(data)中的读操作。我有一个获取事件数组的控制器,然后JSON.serializes该数组(这是JSON字符串,数据访问)。

我不知道时区偏移的问题是什么,我的所有JSON条目数据都与教程架构的字段匹配,但它仍然无法工作...我只需要显示日历通过将此JSON传递给读取操作来打开它时当前存在的所有事件。任何帮助都会非常感激!谢谢。

这是我的控制器:

global with sharing class CalendarData {

public List<Event> eventList{get;set;}
public String jsonString{get;set;}
public List<schedulerItem> correctedItems{get;set;}

public CalendarData(){
    String eventQuery = 'SELECT ActivityDate,ActivityDateTime,CreatedById,Description,DurationInMinutes,EventSubtype,IsAllDayEvent,Location,OwnerId,EndDateTime,StartDateTime,Subject FROM Event';
    eventList = Database.query(eventQuery);
    correctedItems = itemList(eventList);
    system.debug(correctedItems);
    jsonString = JSON.serialize(correctedItems);
    jsonString = jsonString.replace('"EndTime"', '"End"');
}

public List<schedulerItem> itemList(List<Event> events){
        Integer i = 0;
        system.debug(events);
        List<schedulerItem> kendoEvents = new List<schedulerItem>();
        schedulerItem item = new schedulerItem();
        for(i = 0; i < events.size(); i++){
            item.Description = events[i].Description;
            Datetime dt = events[i].EndDateTime;
            item.EndTime = dt.date();
            dt = events[i].StartDateTime;
            item.Start = dt.date();
            item.EndTimezone = 'Etc/UTC';
    //public String id;
            item.IsAllDay = events[i].IsAllDayEvent;
            item.RecurrenceException = null; 
            item.RecurrenceId = null;
            item.RecurrenceRule = null;
            item.StartTimezone = 'Etc/UTC';
            item.Title = events[i].Subject;
            item.TaskId = events[i].Id;
            item.OwnerId = events[i].OwnerId;
            system.debug(item);
            kendoEvents.add(item);

            item = new schedulerItem();
        }
        return kendoEvents;
    }

public class schedulerItem{
    public String Description;
    public Date EndTime;
    public Date Start;
    public String EndTimezone;
    //public String id;
    public Boolean IsAllDay;
    public String RecurrenceException; 
    public String RecurrenceId;
    public String RecurrenceRule;
    public String StartTimezone;
    public String Title;
    public String TaskId;
    public String OwnerId;

}
}

我获取了一个事件列表,然后使用自定义类创建一个新列表,将原始事件列表中的数据绑定到数据名称与教程中的模式模型名称匹配的事件。我也替换了所有&#34; EndTime&#34;用&#34;结束。&#34;

找到一个解决我的事件的解决方案:

var data = '{!jsonString}';
                var dataList = JSON.parse(data);
                function getNewEvents() {
                    var eventList = [];
                    for(var i = 0; i < dataList.length; i++){
                        //console.log("DataList Again: " + dataList[i]);
                        var kendoEvent = new kendo.data.SchedulerEvent({
                            id: i,
                            taskId: dataList[i].TaskId,
                            title: dataList[i].Title,
                            start: new Date(dataList[i].Start),
                            end: new Date(dataList[i].End),
                            startTimezone: dataList[i].StartTimezone,
                            endTimezone: dataList[i].EndTimezone,
                            description: dataList[i].Description,
                            recurrenceId: dataList[i].RecurrenceId,
                            recurrenceRule: dataList[i].RecurrenceRule,
                            recurrenceException: dataList[i].RecurrenceException,
                            ownerId: dataList[i].OwnerId,
                            isAllDay: dataList[i].IsAllDay
                        });
                        eventList.push(kendoEvent);
                    }
                    return eventList;
                }
                eventData = getNewEvents();

我接受了我返回的JSON数组,然后将其解析回一个对象数组,然后创建了一个新的实际kendo.data.SchedulerEvents数组,并用正确的名称填充所有字段。然后在我对数据源的读操作中,而不是URL和数据类型,我做了:

read: function(e){
    e.success(data);
}

数据是我的剑道调度程序事件数组。现在,我的日程表显示了我的组织中的所有事件。现在我将需要处理更新,销毁和创建操作:)。接受的答案的评论中提供的链接帮助我通过必要的文档达到了这个解决方案。

1 个答案:

答案 0 :(得分:1)

我在评论中提到这个问题还有其他原因,但是在查看代码时,其中一个错误是错误的模型配置以及错误的读取配置

JSON中没有传入字段为 EndTime ,而是结束

EndTime 更改为结束,将字段声明与传入的JSON相匹配

{"Title":"meeting","IsAllDay":false,"EndTimezone":"Etc/UTC","End":"2017-01-26", "Description":"a meeting"}

这是Fields声明

    fields: {
                           taskId: { from: "TaskID" },
                           title: { from: "Title", defaultValue: "No title", validation: { required: true } },
                           start: { type: "date", from: "Start" },
 // problem was here there is no EndTime as mentioned in the given code sample above .
// changed to End as it is in the incoming JSON
                           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" }
                      }

有关详细信息,请参阅telerik网站上的此基本示例。

http://demos.telerik.com/kendo-ui/scheduler/index

更正读取配置

请使用此读取我不确定您的控制器是否返回正确的数据并且您的绑定不正确

read: { url: "demos.telerik.com/kendo-ui/service/tasks";, dataType: "jsonp" }