如何使用Reactjs将日历的日期状态发送到另一个日历? [英] How to send the date state of calendar to another calendar with Reactjs?

查看:146
本文介绍了如何使用Reactjs将日历的日期状态发送到另一个日历?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个日历,例如议程,有一个图标日历按钮,当我点击它时,它会被重定向到另一个日历(规划),这些日历是使用 react-big-calendar 开发的,我希望当我在例如导航时议程的一周 juin 17 - 23 ,点击图标日历,它将被重定向到 juin 17 - 23 of the Planning。

I have two calendars, such as the Agenda, have an icon calendar button, when I click on it, it will be redirected to another calendar (Planning), these calendars are developed with react-big-calendar, I want when I navigate for example on the week of juin 17 - 23 of Agenda and I click on the icon calendar, it will be redirected to juin 17 - 23 of the Planning.

我的代码是: https ://codesandbox.io/s/m7k904y3o8

我尝试用 getWeek()发送日期,但它不起作用。

I try to send the date with getWeek(), but it doesn't work.

我该如何解决?

推荐答案

您可以将其他数据添加到 this.props.history.push ,然后将在位置 Planning 组件上的$ c> prop。例如,如果您想查看1995年12月20日的周:

You can add additional data to this.props.history.push which will then be available in the location prop on your Planning component. For example if you want to view the Week of the 20th December 1995:

// Agenda.js: Routing to "/planning"

this.props.history.push("/planning", { date: new Date(1994, 11, 19, 0, 0)})



// Planning.js

constructor(props) {
    super(props); //Important

    this.state({
        /* ... */
        dateWeek: this.props.location.state && this.props.location.state.date
    });
}

// Following is a fix or else you would not get next/previous week.

getThisWeek = (dateWeek) => {
    this.setState({ dateWeek });
}






2我建议的其他解决方案是网址参数查询参数

这篇关于如何使用Reactjs将日历的日期状态发送到另一个日历?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆