我正在尝试使用具有服务器端呈现的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()作用域之外,但如何在其中注入数据呢?我们将非常感谢您的帮助。
3条答案
按热度按时间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]
有关将数据与时间表绑定的更多详细信息,请参阅下面的UG,如果您在这方面需要任何进一步的帮助,请告诉我们。
Https://ej2.syncfusion.com/react/documentation/schedule/data-binding/#data-binding
你好,拉维库马尔·文卡特桑
jv4diomz2#
您可以导入数据源,如下面的代码片段所示,以解决报告的错误。
示例:https://www.syncfusion.com/downloads/support/directtrac/general/ze/ej2-react-next-js-schedule-sample280399184
[index.js]
请试一下附件中的样品,如果您需要进一步的帮助,请告诉我们。
twh00eeo3#
我们建议您参考以下论坛,将日程安排与Mongo DB联系起来。
https://www.syncfusion.com/forums/157730/crud-events-with-express-jshttps://www.syncfusion.com/forums/148981/why-isnt-scheduler-populated-with-appointments-from-my-mongodb-server-using-mongoosehttps://www.syncfusion.com/forums/161378/how-to-make-a-live-update-events-in-schedulehttps://www.syncfusion.com/forums/150433/how-to-use-nodejs-postgresql-mysql-to-crud-schedules?reply=NfZXOIhttps://www.syncfusion.com/forums/143958/data-binding-issue?reply=NSFaXwhttps://www.syncfusion.com/forums/149210/uniquely-identify-each-occurrence-of-recurring-event?reply=SoPOcnhttps://www.syncfusion.com/forums/155045/two-calls-to-the-api-endpoint?reply=NqJMW4
你好,拉维库马尔·文卡特桑