Javascript 如何使用fetch还原带有React fullCalendar的拖放事件?
我有一个react,我想当我拖放事件时,会出现一个带有取消按钮的snackbar,当我单击它时,我会调用拖放的还原功能 我的拖放功能是:Javascript 如何使用fetch还原带有React fullCalendar的拖放事件?,javascript,reactjs,fullcalendar,fetch,fullcalendar-4,Javascript,Reactjs,Fullcalendar,Fetch,Fullcalendar 4,我有一个react,我想当我拖放事件时,会出现一个带有取消按钮的snackbar,当我单击它时,我会调用拖放的还原功能 我的拖放功能是: moveEvent = (info) => { const formData = new FormData(); formData.append('idplanning', info.event.extendedProps.idtranche); formData.append
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)}
/>
this.moveEvent(info)}
/>
当我运行它时,拖放工作正常,但当我单击snackbar的cancel按钮时,将显示最近和旧事件:
我的小吃条:
<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
})
})
}
fetchData=(nom,identificant\u user)=>{
这是我的国家({
事件:[],
EVT存储:[],
事件:[],
evtBackend:[]
})
const praticinsched=JSON.parse(localStorage.getItem('Liste de praticines');
for(设j=0;jResponse.json())
。然后(数据=>{
设evts=data.listResult;
for(设i=0;i
我想,当我点击取消按钮时,只会检索旧事件,而不是最近和旧事件
当我移除
。然后(()=>{
localStorage.removietem('Liste de planning de'+this.state.nom_user);
this.fetchData(this.state.nom_user,this.state.identification_user);
})})
它可以工作,但不能保存在后端
如何修复它?您有多大机会为此创建演示?(或)控制台中有任何错误?请仅尝试删除此:
this.fetchData(this.state.nom_user,this.state.identifiant_user)代码>。可能这个函数正在提取旧数据并覆盖您刚才在ui中所做的操作..Cam是否显示fetchData
函数?该行的作用是什么this.state.evtBackend.push(evts[i])
?您不能直接修改状态,反正看起来您也不需要该行,因为您刚刚调用setState
。也许这就是问题所在。。