javascript - 如何使用 fetch 恢复使用 React fullCalendar 的拖放事件?
问题描述
我有一个反应FullCalendar并且我希望当我拖放事件时,会出现一个带有取消按钮的小吃栏,当我单击它时,我将调用拖放的恢复功能。
我的拖放功能是:
moveEvent = (info) => {
const formData = new FormData();
formData.append('idplanning', info.event.extendedProps.idtranche);
formData.append('bdebug', "0");
formData.append('heuredebut', moment(info.event.start).format('HH:mm'));
formData.append('heurefin', moment(info.event.end).format('HH:mm'));
formData.append('dateplanning', momentStringS);
axios({
method: 'post',
url: process.env.REACT_APP_API_BACKEND+'update_heure_planning/'+this.state.entite,
data: formData,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
})
.then (()=>{
this.setState({
openLoading: true,
infos: info
})
localStorage.removeItem( 'Liste de planning de ' + this.state.nom_user);
this.fetchData(this.state.nom_user, this.state.identifiant_user);
})
}
我的日历是:
<FullCalendar
allDaySlot={false}
defaultView="timeGridWeek"
locale={frLocale}
weekNumbers={true}
plugins={[dayGridPlugin, timeGridPlugin, interactionPlugin]}
ref={this.calendarComponentRef}
events={this.state.events}
displayEventEnd={true}
editable= {true}
selectable={true}
select={this.newEvent}
selectMirror={true}
eventDrop={(info)=>this.moveEvent(info)}
/>
当我运行它时,拖放效果很好,但是当我单击小吃栏的取消按钮时,会出现最近和旧事件:
我的小吃店:
<Snackbar anchorOrigin={{vertical: 'bottom', horizontal: 'center'}}
open={this.state.openLoading}
autoHideDuration={400}
onClose={this.handleCloseLoading}
ContentProps={{ 'aria-describedby': 'message-id' }}
message={<span id="message-id">Enregistrement ...</span>}
action={[
<IconButton
key="close"
aria-label="Close"
color="inherit"
//className={classes.close}
onClick={(this.handleClose)}
>
<CloseIcon />
</IconButton>,
]}
/>
{/* Snackbar d'enregistrement et d'annulation*/}
<Snackbar anchorOrigin={{ vertical: 'bottom', horizontal: 'center'}}
open={this.state.open}
autoHideDuration={6000}
onClose={this.handleClose}
ContentProps={{ 'aria-describedby': 'message-id' }}
message={<span id="message-id">Evénement enregistré</span>}
action={[
<Button key="undo" color="secondary" size="small" onClick={() => this.state.infos.revert()}>
Annuler
</Button>,
<IconButton key="close" aria-label="Close" color="inherit" onClick={this.handleClose}>
<CloseIcon />
</IconButton>,
]}
/>
我的获取是:
fetchData = (nom,identifiant_user) => {
this.setState({
events: [],
evtStorage:[],
prevEvents:[],
evtBackend:[]
})
const praticiensCached = JSON.parse(localStorage.getItem('Liste de praticiens '));
for (let j = 0; j < praticiensCached.length; j++) {
if(this.state.id_user === praticiensCached[j].id_user){
this.state.identifiant_user = praticiensCached[j].identifiant_user;
this.state.nom_user = praticiensCached[j].nom_user;
}
}
/**
* * API de GET Liste de planning
*/
fetch(process.env.REACT_APP_API_BACKEND+'get_liste_planning/'+this.state.entite+'?start='+moment().startOf('isoweek').toJSON()+'&end='+moment().endOf('isoweek').toJSON()+'&identifiant_user='+identifiant_user)
.then(Response => Response.json())
.then(data => {
let evts = data.ListeResult;
for (let i = 0; i < evts.length; i++) {
evts[i].start = moment(evts[i].start).toDate();
evts[i].end = moment(evts[i].end).toDate();
this.state.evtBackend.push(evts[i])
}
this.setState({
evtBackend: evts,
events: evts
})
})
}
我想要什么时候,我点击取消按钮,只会检索旧事件,而不是最近和旧的。
当我删除
.then (()=>{
localStorage.removeItem( 'Liste de planning de ' + this.state.nom_user);
this.fetchData(this.state.nom_user, this.state.identifiant_user);
}) })
它可以工作,但它没有保存在后端。
我该如何解决?
解决方案
推荐阅读
- swift - Xcode Swift MacOs - 隐藏/显示没有 StoryBoard 和 ViewController 的窗口
- c# - 如何找出为什么特定排序较慢
- python - 尝试修改实例变量python时遇到问题
- google-cloud-logging - 在 Cloud Logging 中具有现有过滤器的同时在所有字段中搜索值
- androidpublisher - 是否有明确的 Android Publisher API 错误消息列表
- neural-network - 针对 SNR 范围训练神经网络
- javascript - 操纵动态创建的对象的值?
- python - 如何比较excel工作表名称并将其返回到列表的字典
- python - 为什么 Python 包不像 R 那样附带文档?
- python - 我无法删除出现在 DataFrame 的金额列中的日期