1

我正在使用带有 Angular UI 的 arshaw 出色的 fullcalendar,现在我遇到扩展形式的 eventSource 对象在作为 JSON 提要获取时无法呈现的问题。

使用控制器中的以下代码获取数据:

$scope.events = [   
  '/api/v1/users/104/events?format=cal&type=9',
  '/api/v1/users/104/events?format=cal&type=10'
];
$scope.eventSources = $scope.events;

当 JSON 提要返回一个包含事件对象的数组时,它实际上可以工作:

// returned by - /api/v1/users/104/events?format=cal&type=9
[
  {
    url: "/#/events/86893",
    start: "2013-03-15",
    title: ": Event - 86893"
  },
  {
    url: "/#/events/31348",
    start: "2013-03-27T09:30Z",
    title: "Event - 31348"
  }
],
// returned by - /api/v1/users/104/events?format=cal&type=10
[
  {
    url: "/#/events/86899",
    start: "2013-03-25",
    title: ": Event - 86899"
  },
  {
    url: "/#/events/31349",
    start: "2013-03-17T09:30Z",
    title: "Event - 31349"
  }
]

但是,我想指定一些选项以及事件数据,例如不同 JSON 提要的不同颜色。因此,我决定让 API 以其扩展形式返回事件源。这就是它 API 返回的内容。

// returned by - /api/v1/users/104/events?format=cal&type=9
{
  events: [
    {
      url: "/#/events/86893",
      start: "2013-03-15",
      title: "Event - 86893"
    },
    {
      url: "/#/events/31348",
      start: "2013-03-27T09:30Z",
      title: "Event - 31348"
    }
  ],
  color: "#ff9900",
  allDayDefault: false,
  ignoreTimezone: true
},
// returned by - /api/v1/users/104/events?format=cal&type=10
{
  events: [
    {
      url: "/#/events/86899",
      start: "2013-03-25",
      title: "Event - 86899"
    },
    {
      url: "/#/events/31349",
      start: "2013-03-17T09:30Z",
      title: "Event - 31349"
    }
  ],
  color: "#3366FF",
  allDayDefault: false,
  ignoreTimezone: true
}

不幸的是,这种格式在以 JSON 格式获取时不会呈现。在获取扩展格式时,我将 eventSources 分配更改为如下所示:

$scope.eventSources = [ $scope.events ];

如果我将 API 中的原始 JSON 响应(事件源的扩展形式)直接剪切并粘贴到 eventSources 方法中,它就可以工作。当事件源作为 JSON 提要返回时,是否可以使用扩展形式的事件源?

4

1 回答 1

0

会不会是从 API 返回的 eventSource 不是应该使用扩展表单选项的地方,而是在用作 eventSource 的事件函数中。

该文档指出,扩展形式应在用于调用 API 的 Json 对象内部使用。

http://arshaw.com/fullcalendar/docs/event_data/events_json_feed/

如果 API 过于返回事件的额外选项,则需要单独设置每个选项。

目前在这篇文章中,我看到调用扩展选项的唯一地方是返回的 api 数据。

我认为这应该反过来。日历甚至在请求数据之前就应该知道扩展表单。这意味着服务器不需要返回任何额外的选项,日历将按提要和扩展选项组织事件对象。

如果您可以发布一个 plunk,那么我们可以解决这个问题。

于 2013-03-16T07:09:00.843 回答