在devextreme scheduler的插件上刷新错误 - 角度4

时间:2017-09-12 12:20:52

标签: javascript angular devexpress scheduler devextreme

我正在尝试使用devextreme调度程序创建预约调度程序的应用程序。 我有一个小虫子。我想知道为什么,当我创建一个约会并拖放约会我刚创建我在我的控制台上有这个错误:

PUT http://localhost/v0/croissant/undefined 404 (Not Found)
appointment.service.ts:19 An error occurred Response {_body: "", status: 404, ok: false, statusText: "Not Found", headers: Headers…}
webpackJsonp.../../../../../src/app/services/appointment.service.ts.AppointmentService.handleError @ appointment.service.ts:19
ZoneDelegate.invoke @ zone.js:203
onInvoke @ core.es5.js:3890
ZoneDelegate.invoke @ zone.js:202
Zone.run @ zone.js:96
(anonymous) @ zone.js:462
ZoneDelegate.invokeTask @ zone.js:236
onInvokeTask @ core.es5.js:3881
ZoneDelegate.invokeTask @ zone.js:235
Zone.runTask @ zone.js:136
drainMicroTaskQueue @ zone.js:368
ZoneTask.invoke @ zone.js:308
core.es5.js:1020 ERROR Error: Uncaught (in promise): Response with status: 404 Not Found for URL: http://localhost/v0/croissant/undefined

但是当我刷新页面然后移动约会时,一切正常......

这是我的约会上的更新约会方法.Service.ts

updateAppointment(id: string, userId :string, timestamp :string, reason: string): Promise<Appointment>{

    let bodySearchParam = new URLSearchParams();
    bodySearchParam.append('userId', userId );
    bodySearchParam.append('timestamp', this.datetotimestamp(timestamp).toString());
    bodySearchParam.append('reason', reason);
    let body = bodySearchParam.toString();


    var AppointmentUrlUpdate = this.AppointmentUrlWrite + "/" + id;

    return this.http.put(AppointmentUrlUpdate, body)
                    .toPromise()
                    .then(response =>
                      console.log("event updated")
                    )
                    .catch(this.handleError);

  }

这是我的日历组件上的eventHandler

  updateAppointment(e: any){
    e.appointmentData.endDate = this.add30mnTo(e.appointmentData.startDate); // bugFix pour l'affichage du calendrier
    this.appointmentService.updateAppointment(e.appointmentData.id, e.appointmentData.ownerId, e.appointmentData.startDate, e.appointmentData.text)
  }

这是我在calendar.component.html

上调用我的eventHandler的地方
<dx-scheduler
    (onAppointmentUpdated)= "updateAppointment($event)"
>

</dx-scheduler>

谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

问题是,我的api需要和ID来更新约会。但是id目前还没有存储。决议的方法是:

  createAppointment(userId :string, timestamp :string, reason: string): Promise<Appointment> {

    let bodySearchParam = new URLSearchParams();
    bodySearchParam.append('userId', userId );
    bodySearchParam.append('timestamp', this.datetotimestamp(timestamp).toString());
    bodySearchParam.append('reason', reason);
    let body = bodySearchParam.toString();

    console.log(body)
    return this.http.post(this.AppointmentUrlWrite,body)
                  .toPromise()
                  .then(response =>
                    this.createdId = response.json().id // Get the appointment's ID
                  )
                  .catch(this.handleError);
  }

创建一个返回createdID的函数:

  getCreatedId(){
    return this.createdId;
  }

并在updateAppointment方法上执行此操作:

if(e.appointmentData.id == null){e.appointmentData.id = this.appointmentService.getCreatedId();}

条件用于已经拥有id的约会(刷新页面后所有约会都有一个id)

希望它能为另一个服务:)