正在尝试翻译Nextjs中使用的ReactScheduler

c3frrgcw  于 2022-10-21  发布在  React
关注(0)|答案(3)|浏览(127)

我正在尝试使用具有服务器端呈现的Next.js将@syncsion/ej2-action-Schedule调度程序翻译成法语。因此,我正在转换@syncfusion/ej2-action-Schedule基本代码,使其在NEXT中与服务器端呈现一起运行。我在用于在返回()方法中呈现调度程序的JSX标记内的数据注入中遇到数据填充错误。数据是在Reaction功能组件js文件中导入的基本JSON文件。

import { render } from "react-dom";
import "./../../styles/agenda.module.css";
import * as React from "react";
import {
  ScheduleComponent,
  Day,
  Week,
  WorkWeek,
  Month,
  Agenda,
  Inject,
  Resize,
  DragAndDrop
} from "@syncfusion/ej2-react-schedule";

import { extend, loadCldr, L10n } from "@syncfusion/ej2-base";
import { SampleBase } from "./sample-base";

import * as dataSource from "../../database/agenda_datasource.json";
import * as numberingSystems from "./../agenda-culture-files/numberingSystems.json";
import * as gregorian from "../agenda-culture-files/ca-gregorian.json";
import * as numbers from "../agenda-culture-files/numbers.json";
import * as timeZoneNames from "../agenda-culture-files/timeZoneNames.json";
import dynamic from 'next/dynamic';

//Dynamically import the Smart.Scheduler component
const Scheduler = dynamic(() => import("@syncfusion/ej2-react-schedule"), {
  ssr: false, //no server-side rendering 

});

function AgendaWidget({}) {
  loadCldr(numberingSystems, gregorian, numbers, timeZoneNames);
// hoho ny tsy fahaizana ajax de atao manta be lo le traduction fa ra mazoto any aoriana de ito ny code snipet https://ej2.syncfusion.com/react/documentation/schedule/localization/
L10n.load({
  fr: {
  ////.............. json translating contents
    },
    calendar: {
      today: "Aujourd'hui,Androany"
    }
  }
});
 var predatabase = dataSource;
 var database = {predatabase:this.data}
  return (

    <Scheduler
    width="100%"
    height="650px"
    selectedDate={new Date(2018, 1, 15)}
    ref={t => (this.scheduleObj = t)}
//why it can't find  database variable here
    eventSettings={database}
    locale="es"
  >
    <Inject
      services={[
        Day,
        Week,
        WorkWeek,
        Month,
        Agenda,
        Resize,
        DragAndDrop
      ]}
    />
  </Scheduler>
  );
}

export default AgendaWidget;

The error

   TypeError: Cannot read property 'data' of undefined

    This error happened while generating the page. Any console logs will be displayed in the terminal window

 162 | });
  163 |  var predatabase = dataSource;
> 164 |  var database = {predatabase:this.data}
      |                                  ^
  165 |   return (
  166 |     
  167 |     <Scheduler

我知道数据库变量不在Return()作用域之外,但如何在其中注入数据呢?我们将非常感谢您的帮助。

62o28rlo

62o28rlo1#

我们已在我们端验证了您的查询“TypeError:无法读取未定义的属性‘data’”。在您的共享代码片段中,您将“this.data”设置为DATABASE变量的predatabase属性,这是问题的根本原因。您不能在功能组件中使用This。此外,您的共享代码片段中没有数据命名的变量。但是,您已将“this.data”分配给predatabase属性。要解决该问题,您需要将数据源设置为时间表,如下面的代码片段所示。

示例:https://www.syncfusion.com/downloads/support/directtrac/general/ze/ej2-react-next-js-schedule-sample-1127783108
[index.js]

import * as dataSource from './datasource.json';

export default function Home() {
  var predatabase = extend([], dataSource.zooEventsData, null, true);
  const database = { dataSource: predatabase };
  return (
    <div className="container">
      <ScheduleComponent width="100%" height="650px" selectedDate={new Date(2021, 1, 15)} locale="es" eventSettings={database}>
        <Inject services={[Day, Week, WorkWeek, Month, Agenda, DragAndDrop, Resize]} />
      </ScheduleComponent>
    </div>
  )
}

有关将数据与时间表绑定的更多详细信息,请参阅下面的UG,如果您在这方面需要任何进一步的帮助,请告诉我们。
Https://ej2.syncfusion.com/react/documentation/schedule/data-binding/#data-binding
你好,拉维库马尔·文卡特桑

jv4diomz

jv4diomz2#

您可以导入数据源,如下面的代码片段所示,以解决报告的错误。

示例:https://www.syncfusion.com/downloads/support/directtrac/general/ze/ej2-react-next-js-schedule-sample280399184
[index.js]

import * as timeZoneNames from "../culture-files/main/timeZoneNames.json";
import {default as dataSource} from './datasource.json';
import "../node_modules/@syncfusion/ej2-base/styles/material.css";

请试一下附件中的样品,如果您需要进一步的帮助,请告诉我们。

相关问题