英文:
FullCalendar listview is list in calendar view
问题
I'm new to FullCalendar. I'm using React, and I want to render "listDay" and "listWeek," but they come out as "list" in the calendar view on the web.
import React, { useState } from "react";
import FullCalendar from "@fullcalendar/react";
import daygridPlugin from "@fullcalendar/daygrid";
import timeGridPlugin from "@fullcalendar/timegrid";
import interactionPlugin from "@fullcalendar/interaction";
import listPlugin from "@fullcalendar/list";
export default function Calendar() {
return (
<div>
<FullCalendar
editable
selectable
events={events}
headerToolbar={{
start: "today prev next",
center: "title",
end: "dayGridMonth timeGridWeek timeGridDay listWeek listDay",
}}
plugins={[listPlugin, daygridPlugin, timeGridPlugin, interactionPlugin]}
views={[
"dayGridMonth",
"timeGridWeek",
"timeGridDay",
"listDay",
"listWeek",
]}
validRange={[
{
start: "2023-05-11",
end: "2023-06-11",
},
]}
/>
</div>
);
}
I have tried the following:
views={[
"dayGridMonth",
"timeGridWeek",
"timeGridDay",
"listDay",
"listWeek",
]}
buttonText={[
{
listWeek: "List Week",
listDay: "List Day",
},
]}
And something starting with:
var calendar = new Calendar(calendarEl, {})
But it seems as though the calendarEl
is not for React.
Is there a React alternative to calendarEl
as it is referenced quite a lot in the documentation?
英文:
i'm new to FullCalendar. i'm using React and i want to render listDay
and listWeek
but they come out as "list" in the calendar view on the web.
import React, { useState } from "react";
import FullCalendar from "@fullcalendar/react";
import daygridPlugin from "@fullcalendar/daygrid";
import timeGridPlugin from "@fullcalendar/timegrid";
import interactionPlugin from "@fullcalendar/interaction";
import listPlugin from "@fullcalendar/list";
export default function Calendar() {
return (
<div>
<FullCalendar
editable
selectable
events={events}
headerToolbar={{
start: "today prev next",
center: "title",
end: "dayGridMonth timeGridWeek timeGridDay listWeek listDay",
}}
plugins={[listPlugin, daygridPlugin, timeGridPlugin, interactionPlugin]}
views={[
"dayGridMonth",
"timeGridWeek",
"timeGridDay",
"listDay",
"listWeek",
]}
validRange={[
{
start: "2023-05-11",
end: "2023-06-11",
},
]}
/>
</div>
);
}
I have tried the following:
views={[
"dayGridMonth",
"timeGridWeek",
"timeGridDay",
"listDay",
"listWeek",
]}
buttonText={[
{
listWeek: "List Week",
listDay: "List Day",
},
]}
And something starting with:
var calendar = new Calendar(calendarEl, {})
but it seems as though the calendarEl
is not for React.
Is there a React alternative to calendarEl
as it is referenced quite alot in the documentation?
答案1
得分: 1
I encountered similar problem (but not quite the same) the first time I run the example project from FullCalendar repo
This is the code I tried:
import FullCalendar from "@fullcalendar/react";
import dayGridPlugin from "@fullcalendar/daygrid";
import interactionPlugin from "@fullcalendar/interaction";
import timeGridPlugin from "@fullcalendar/timegrid";
import listPlugin from "@fullcalendar/list";
return (
<FullCalendar
editable
selectable
headerToolbar={{
start: "today prev next",
center: "title",
end: "dayGridMonth timeGridWeek timeGridDay listWeek listDay",
}}
events="https://fullcalendar.io/api/demo-feeds/events.json"
plugins={[
dayGridPlugin,
timeGridPlugin,
interactionPlugin,
listPlugin,
]}
buttonText= {{
listWeek: 'List Week',
listDay: 'List Day'
}}
/>
)
Below was the result. Both listWeek
and listDay
button appeared without label/text.
Turned out, It was because I did not install the @fullcalendar/list
on my project. On their readme here, they don't instruct to install the list
package to begin with. So then, I manually installed it using command npm i @fullcalendar/list
After that, the button label/text appeared.
Without putting the buttonText
prop, the button labels will be just "list" like on the screenshot you posted.
英文:
I encountered similar problem (but not quite the same) the first time I run the example project from FullCalendar repo
This is the code I tried:
import FullCalendar from "@fullcalendar/react";
import dayGridPlugin from "@fullcalendar/daygrid";
import interactionPlugin from "@fullcalendar/interaction";
import timeGridPlugin from "@fullcalendar/timegrid";
import listPlugin from "@fullcalendar/list";
return (
<FullCalendar
editable
selectable
headerToolbar={{
start: "today prev next",
center: "title",
end: "dayGridMonth timeGridWeek timeGridDay listWeek listDay",
}}
events="https://fullcalendar.io/api/demo-feeds/events.json"
plugins={[
dayGridPlugin,
timeGridPlugin,
interactionPlugin,
listPlugin,
]}
buttonText= {{
listWeek: 'List Week',
listDay: 'List Day'
}}
/>
)
Below was the result. Both listWeek
and listDay
button appeared without label/text.
Turned out, It was because I did not install the @fullcalendar/list
on my project. On their readme here, they don't instruct to install the list
package to begin with. So then, I manually installed it using command npm i @fullcalendar/list
After that, the button label/text appeared.
Without putting the buttonText
prop, the button labels will be just "list" like on the screenshot you posted.
答案2
得分: 0
以下是翻译好的内容:
"buttonText"属性可以用于实现你想要的效果。
在常规的JS中,可以这样写:
buttonText: {
"listWeek": "List Week",
"listDay": "List Day"
}
我不是React用户,但根据文档和其他地方的示例推断,由于"buttonText"数据是一个对象而不是数组,我认为你需要使用以下语法:
buttonText={{
"listWeek": "List Week",
"listDay": "List Day"
}}
演示演示了"buttonText"的效果(使用原生JS,因为我不是React用户):https://codepen.io/ADyson82/pen/XWxqOdv
另外,fullCalendar文档中没有"views"选项,所以我不确定你的代码中使用它的想法是从哪里来的,或者你认为它是做什么的。
此外,你还问道:
"是否有React替代品来代替calendarEl?"
没有,也不需要,因为"calendarEl"是一个原生DOM对象,你将其传递给日历,以便它知道在页面上渲染日历的位置。而在React中,据我了解,你声明"<FullCalendar"组件并在页面的适当位置使用它,而不需要直接引用原生DOM。
但是,如果你想要获得与"calendar"变量等效的内容,这在Fullcalendar React组件的指南中有记录 - 阅读标题为"Calendar API"的部分,了解如何检索一个对象,然后可以访问所有fullCalendar的函数。然而,对于你的问题,你应该不需要它。
英文:
You're right that buttonText can be used to achieve what you want.
In regular JS, this would be written as:
buttonText: {
"listWeek": "List Week",
"listDay": "List Day"
}
I'm not a React user, but inferring from the examples in the documentation and elsewhere, since the buttonText
data is an object rather than an array, I think the syntax you need to use should be as follows:
buttonText={{
"listWeek": "List Week",
"listDay": "List Day"
}}
Demo showing buttonText
in action (using vanilla JS, since, again, I'm not a React user): https://codepen.io/ADyson82/pen/XWxqOdv
P.S. There is no views
option in the fullCalendar documentation so I'm not sure where the idea for using that in your code came from, or what you think it does.
P.P.S. You also asked
> Is there a React alternative to calendarEl
No, and there needn't be, because calendarEl
is a native DOM object which you pass into the calendar, so it knows where to render the calendar on the page. Whereas in React, as a I understand it, you declare the <FullCalendar
component and use that in a suitable place in your page, without needing to directly refer to the native DOM.
If however, you wanted to get an equivalent for the calendar
variable, this is documented in the guidance for the Fullcalendar React component - read the section entitled "Calendar API" to find out how to retrieve an object which then gives you access to all of fullCalendar's functions. However for the task in your question, you should not need it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论