0

我正在尝试将功能添加到我的完整日历应用程序中,当用户单击某个事件时,它将复制它(稍后将移动)。

问题是重复的事件虽然存在,但不会显示。

起初我认为这可能是一个resourceID问题。但是,我通过添加资源 ID 属性来消除这种恐惧。我真的不确定此时问题是什么,因为这两个元素在功能上是相同的(尽管它们是用不同的 ID 制作的)。

我的代码示例是(标记了重复块//Duplication):

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<link href='../packages/core/main.css' rel='stylesheet' />
<link href='../packages/daygrid/main.css' rel='stylesheet' />
<link href='../packages/timegrid/main.css' rel='stylesheet' />
<link href='../packages/list/main.css' rel='stylesheet' />
<link href='../packages/timeline/main.css' rel='stylesheet' />
<link href='../packages/resource-timeline/main.css' rel='stylesheet' />
<script src='../packages/core/main.js'></script>
<script src='../packages/interaction/main.js'></script>
<script src='../packages/daygrid/main.js'></script>
<script src='../packages/timegrid/main.js'></script>
<script src='../packages/list/main.js'></script>
<script src='../packages/timeline/main.js'></script>
<script src='../packages/resource-common/main.js'></script>
<script src='../packages/resource-timeline/main.js'></script>
<script>

 document.addEventListener("DOMContentLoaded", function() {
  var calendarEl = document.getElementById("calendar");

  var calendar = new FullCalendar.Calendar(calendarEl, {
    plugins: ["resourceTimeline"],
    now: "2019-03-19",
    header: {
      left: "today prev,next",
      center: "title",
      right: "resourceTimelineDay,resourceTimelineWeek"
    },
    aspectRatio: 1.6,
    defaultView: "resourceTimelineDay",
    resources: [
      { id: "a", title: "Auditorium A" },
      { id: "b", title: "Auditorium B" }
    ],

    events: [
      {
        id: "1",
        resourceId: "a",
        start: "2019-03-19T08:00:00",
        end: "2019-03-07T07:00:00",
        title: "event 1"
      },
      {
        id: "2",
        resourceId: "b",
        start: "2019-03-19T10:00:00",
        end: "2019-03-07T22:00:00",
        title: "event 2"
      }
    ],

    // Duplication
    eventClick: function(arg) {
      dupedEvent = calendar.addEvent({
        title: arg.event.title,
        start: arg.event.start,
        end: arg.event.end,
        id: Math.random(),
        resourceIds: arg.event.resourceIds
      });

      console.log("Orginial: ", arg.event);
      console.log("Duplicate: ", dupedEvent)
    }
  });

  calendar.render();
});


</script>
<style>

  body {
    margin: 0;
    padding: 0;
    font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
    font-size: 14px;
  }

  #calendar {
    max-width: 900px;
    margin: 50px auto;
  }

</style>
</head>
<body>

  <div id='calendar'></div>

</body>
</html>

如果有人想看看的话,一个工作的codepen: https ://codepen.io/anon/pen/JzBwwj?editors=0010

4

1 回答 1

1

如果您查看正在记录的对象,则副本没有 resourceIds,如果您尝试记录arg.event.resourceIds它是未定义的,因此不会在副本上设置。那就是他们没有被渲染的原因。它们不与资源相关联。

您可以使用事件对象上的方法getResources从事件中获取资源。那将是正确的方法,但是我确实设法让它渲染设置 resourceIds from arg.event._def.resourceIds

建议的解决方案:

  dupedEvent = calendar.addEvent({
    title: arg.event.title,
    start: arg.event.start,
    end: arg.event.end,
    id: Math.random(),
    resourceIds: arg.event.getResources().map(resource => resource.id)
  });
}
于 2019-03-19T14:33:47.780 回答