gpt4 book ai didi

javascript - 使用 calendar.AddEvent 在 FullCalendar Scheduler 4.0.1 中复制事件

转载 作者:行者123 更新时间:2023-12-02 23:59:24 26 4
gpt4 key购买 nike

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

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

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

我的代码示例是(重复 block 标记为//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>

如果有人想看的话,这是一个可用的代码笔: https://codepen.io/anon/pen/JzBwwj?editors=0010

最佳答案

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

您可以使用 getResources 从事件中获取资源,事件对象上的方法。这将是正确的方法,但是我确实设法让它渲染设置来自 arg.event._def.resourceIds 的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)
});
}

关于javascript - 使用 calendar.AddEvent 在 FullCalendar Scheduler 4.0.1 中复制事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55240774/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com