我使用react-big-calender创建了一个简单的事件拖放操作。通常,仅是文档中提供的示例代码的复制粘贴。以下是我创建的事件dnd的代码:
dnd.js
import React from 'react'
import events from './events'
import HTML5Backend from 'react-dnd-html5-backend'
import { DragDropContext } from 'react-dnd'
import BigCalendar from 'react-big-calendar'
import withDragAndDrop from 'react-big-calendar/lib/addons/dragAndDrop';
import 'react-big-calendar/lib/css/react-big-calendar.css';
import 'react-big-calendar/lib/addons/dragAndDrop/styles.css';
const DragAndDropCalendar = withDragAndDrop(BigCalendar)
class Dnd extends React.Component {
constructor(props) {
super(props)
this.state = {
events: events,
}
this.moveEvent = this.moveEvent.bind(this)
}
moveEvent({ event, start, end }) {
const { events } = this.state
const idx = events.indexOf(event)
const updatedEvent = { ...event, start, end }
const nextEvents = [...events]
nextEvents.splice(idx, 1, updatedEvent)
this.setState({
events: nextEvents,
})
alert(`${event.title} was dropped onto ${event.start}`)
}
resizeEvent = (resizeType, { event, start, end }) => {
const { events } = this.state
const nextEvents = events.map(existingEvent => {
return existingEvent.id == event.id
? { ...existingEvent, start, end }
: existingEvent
})
this.setState({
events: nextEvents,
})
alert(`${event.title} was resized to ${start}-${end}`)
}
render() {
return (
<DragAndDropCalendar
selectable
events={this.state.events}
onEventDrop={this.moveEvent}
resizable
onEventResize={this.resizeEvent}
defaultView="week"
defaultDate={new Date(2015, 3, 12)}
/>
)
}
}
export default DragDropContext(HTML5Backend)(Dnd)
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import Knight from './knight/knight';
import Square from './square/square';
import Board from './board/board';
import Dnd from './bigcalender/dnd';
import { moveKnight , observe } from './game';
import BigCalendar from 'react-big-calendar'
import CustomCalLoader from './customCal/customCalLoader';
import SimpleDrag from './simpleDrag/simpleDrag';
import moment from 'moment';
BigCalendar.momentLocalizer(moment);
const rootEl = document.getElementById('root');
ReactDOM.render(
<Dnd />,
rootEl
)
要使此示例正常工作,必须使用react-DND包。我现在想做的是,添加将外部事件放入日历中的功能,例如THIS。我如何使用React Big Calendar和React DND来实现此目标?