在fullcalendar中为每个EventInput设置ID

时间:2019-11-15 11:57:32

标签: angular fullcalendar

我有以下EventInput

 calendarEvents: EventInput[] = [
    {
      title: "Event Now - 1",
      start: new Date().setHours(10)
    },
    {
      title: "Event Now - 2",
      start: new Date()
    }
  ];

和在HTML中:

(eventClick)="selectedEvent($event)"

是否可以为每个EventInput设置ID并通过selectedEvent方法获取该ID,因为我想获取数据形式Api以基于Id的模式显示?

  selectedEvent($event) {
   // get Id in here ...
    console.log($event.view);
  }

Stackblitz Here ...

1 个答案:

答案 0 :(得分:2)

尝试这样:

  selectEvent($event) {
    console.log($event.event.title);
  }

您还可以在对象中设置id属性,

  calendarEvents: EventInput[] = [
    {
      id:1,
      title: "Event Now - 1",
      start: new Date().setHours(10)
    },
    {
      id:2,
      title: "Event Now - 2",
      start: new Date()
    }
  ];

并像这样获得id

  selectEvent($event) {
    console.log($event.event.id);
  }

Working Demo