FullCalendar列表视图是在日历视图中的列表。

huangapple go评论66阅读模式
英文:

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.

FullCalendar列表视图是在日历视图中的列表。

import React, { useState } from &quot;react&quot;;
import FullCalendar from &quot;@fullcalendar/react&quot;;
import daygridPlugin from &quot;@fullcalendar/daygrid&quot;;
import timeGridPlugin from &quot;@fullcalendar/timegrid&quot;;
import interactionPlugin from &quot;@fullcalendar/interaction&quot;;
import listPlugin from &quot;@fullcalendar/list&quot;;

export default function Calendar() {
return (
    &lt;div&gt;
      &lt;FullCalendar
        editable
        selectable
        events={events}
        headerToolbar={{
          start: &quot;today prev next&quot;,
          center: &quot;title&quot;,
          end: &quot;dayGridMonth timeGridWeek timeGridDay listWeek listDay&quot;,
        }}
        plugins={[listPlugin, daygridPlugin, timeGridPlugin, interactionPlugin]}
        views={[
          &quot;dayGridMonth&quot;,
          &quot;timeGridWeek&quot;,
          &quot;timeGridDay&quot;,
          &quot;listDay&quot;,
          &quot;listWeek&quot;,
        ]}
        validRange={[
          {
            start: &quot;2023-05-11&quot;,
            end: &quot;2023-06-11&quot;,
          },
        ]}
      /&gt;
    &lt;/div&gt;
  );
}

I have tried the following:

views={[
          &quot;dayGridMonth&quot;,
          &quot;timeGridWeek&quot;,
          &quot;timeGridDay&quot;,
          &quot;listDay&quot;,
          &quot;listWeek&quot;,
        ]}
        buttonText={[
          {
            listWeek: &quot;List Week&quot;,
            listDay: &quot;List Day&quot;,
          },
        ]}

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.

FullCalendar列表视图是在日历视图中的列表。

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.

FullCalendar列表视图是在日历视图中的列表。

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 &quot;@fullcalendar/react&quot;;
import dayGridPlugin from &quot;@fullcalendar/daygrid&quot;;
import interactionPlugin from &quot;@fullcalendar/interaction&quot;;
import timeGridPlugin from &quot;@fullcalendar/timegrid&quot;;
import listPlugin from &quot;@fullcalendar/list&quot;;

  return (
    &lt;FullCalendar
      editable
      selectable
      headerToolbar={{
        start: &quot;today prev next&quot;,
        center: &quot;title&quot;,
        end: &quot;dayGridMonth timeGridWeek timeGridDay listWeek listDay&quot;,
      }}
      events=&quot;https://fullcalendar.io/api/demo-feeds/events.json&quot;
      plugins={[
        dayGridPlugin,
        timeGridPlugin,
        interactionPlugin,
        listPlugin,
      ]}
      buttonText= {{
        listWeek: &#39;List Week&#39;,
        listDay: &#39;List Day&#39;
      }}
    /&gt;
  )

Below was the result. Both listWeek and listDay button appeared without label/text.

FullCalendar列表视图是在日历视图中的列表。

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.

FullCalendar列表视图是在日历视图中的列表。

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: {
  &quot;listWeek&quot;: &quot;List Week&quot;,
  &quot;listDay&quot;: &quot;List Day&quot;
}

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={{
  &quot;listWeek&quot;: &quot;List Week&quot;,
  &quot;listDay&quot;: &quot;List Day&quot;
}}

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 &lt;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.

huangapple
  • 本文由 发表于 2023年5月11日 20:01:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76227442.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定