加载资源作为 JSON 提要时的方法问题

Problem with methods when loading resources as a JSON feed

从包含 JSON 提要的远程脚本加载资源时,我在使用 getResources 和 addResource 等方法时遇到问题。

如果将相同的资源作为数组包含在内,它就可以正常工作。 工作示例:

resources: [{"id":"a","title":"Auditorium A"},{"id":"b","title":"Auditorium B","eventColor":"green"}....

https://codepen.io/ProbablyTheRealJonas/pen/yLVzEJw

不工作:

resources: 'https://fullcalendar.io/demo-resources.json?with-nesting&with-colors',

https://codepen.io/ProbablyTheRealJonas/pen/BaQwVjY

我可能遗漏了什么?

我认为这与您尝试在调用 calendar.render() 后立即添加资源这一事实有关——我认为这不是一个真正的现实场景——但忘记了加载资源来自远程 URL 是 异步 .

因此,它很可能在您调用 addResource 和 getResources 之后从服务器加载资源,这就是您看不到任何内容的原因。 (我假设这就是你所说的“不工作”和“有问题”的意思——你对实际问题的表述非常含糊。)

如果您创建一个“添加资源”按钮并将 addResources 和 getResources 的代码移动到其中,那么一旦单击该按钮它们就可以正常工作 - 因为到那时其他资源就有机会从服务器加载.

例如

<button type="button" id="addR">Add Resource</button>

  document.getElementById("addR").addEventListener("click", function () {
    calendar.addResource({
      id: "eeeee",
      title: "Room EEEEE"
    });
    var testing = calendar.getResources();
    console.log(testing.length);
  });

演示:https://codepen.io/ADyson82/pen/oNYGOMN