我正在使用 FullCalendar 开发一个网络系统。
我正在尝试像使用 eventClick 一样自定义带有链接的资源标题,但我自定义的代码无法按预期工作。
有人可以帮忙解决这个案子吗?
提前谢谢你。
原码
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'/>
<style>
html, body {
margin: 0;
padding: 0;
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
font-size: 14px;
}
#calendar {
max-width: 900px;
margin: 40px auto;
}
</style>
<link href='https://unpkg.com/@fullcalendar/[email protected]/main.min.css' rel='stylesheet'/>
<link href='https://unpkg.com/@fullcalendar/[email protected]/main.min.css' rel='stylesheet'/>
<link href='https://unpkg.com/@fullcalendar/[email protected]/main.min.css' rel='stylesheet'/>
<script src='https://unpkg.com/@fullcalendar/[email protected]/main.min.js'></script>
<script src='https://unpkg.com/@fullcalendar/[email protected]/main.min.js'></script>
<script src='https://unpkg.com/@fullcalendar/[email protected]/main.min.js'></script>
<script src='https://unpkg.com/@fullcalendar/[email protected]/main.min.js'></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: ['resourceTimeline'],
defaultView: 'resourceTimelineDay',
header: {
left: 'prev,next',
center: 'title',
right: 'resourceTimelineDay,resourceTimelineWeek,resourceTimelineMonth'
},
resourceLabelText: 'Rooms',
resources: [
{id: 'a',
title: 'room1',
url: 'http://google.com/'
},
],
});
calendar.render();
});
</script>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
我添加的引用事件点击的代码
resourceClick: function (info) {
info.jsResource.preventDefault();
if (info.resource.url) {
window.open(info.resource.url);
}
},
我也试过像下面这样的 resourceRender 但它不起作用......
resources: [
{
id: 'a',
title: '<a href="http://google.com/">room1</a>',
},
],
resourceRender: function (renderInfo,element) {
element.find('span.fc-title').html(element.find('span.fc-title').text());
}
我的开发环境
这是我解决问题的方法:
resourceRender: function (resourceObj, $th) {
$th.html(
$('<a href="http://google.com/">' + resourceObj.title + '</a>')
);
},
对于在 React 中遇到同样问题的人。这是我的解决方案。基于以上答案
resourceLabelContent={(resourceObject) => {
return {
html:
`<a class="c-table__link" href=/users/${resourceObject.resource.id}>` +
resourceObject.resource.title +
`</a>`,
};
}}