首页 > 解决方案 > 如何访问 Fullcalendar 中的 JSON 字段?

问题描述

我正在用 PHP/jQuery 开发一个约会工具。我将所有约会作为 JSON 对象获取,如下所示:

[
  {
    "title": "Appointment with Zach Green{3}",
    "appointment_id": "3",
    "start": "2019-01-30T10:30:00",
    "end": "2019-01-30T11:45:00",
    "backgroundColor": "#226fbe",
    "borderColor": "#226fbe"
  },
  {
    "title": "Appointment with Mark Sammons{4}",
    "appointment_id": "4",
    "start": "2019-01-29T11:30:00",
    "end": "2019-01-29T12:45:00",
    "backgroundColor": "#226fbe",
    "borderColor": "#226fbe"
  }
]

目前,我appointment_id通过附加到标题并在 jQuery 中解析 id 来传递。但是,appointment_id它显示在我想避免的日历上。

附上日历截图

在此处输入图像描述

在此处输入图像描述

知道怎么做吗?

标签: javascriptjqueryjsonfullcalendar

解决方案


您可以设置自定义属性并从事件中获取它,而不是传递标题。

例如:

<input type="hidden" data-id="yourid here" class="appoimentId">

$('.appoimentId').click(function(){
   //id on each item click
   console.log($(this).attr('data-id'));
})

推荐阅读