从eventReceive获取id

时间:2015-12-29 02:55:55

标签: javascript jquery html fullcalendar

我尝试从 div 中获取 id 属性值并输入日历。我尝试了许多方法但没有成功。

我创建了以下 div

vv_lista_servico = vv_lista_servico +"<div class='fc-event fc-list draggable' data-event='{\"id\":\""+item.id+"\"}' data-duration='00:30'>"+item.descr+"</div>";

准备好后,我有以下html:

<div class="fc-event fc-list draggable ui-draggable ui-draggable-handle" data-event="{"id":"244"}" data-duration="00:30">Test 1</div>

当我将事件拖入fullcalendar时,我的标题和持续时间在日历上工作并呈现,但id不起作用。

我应该如何创建我的html才能运行并获取ID?

感谢&#39; S

1 个答案:

答案 0 :(得分:1)

根据eventReceive文档,事件数据需要是有效的JSON,因此数据事件中的双引号:

<div class='fc-event' data-event='{"id": 1, "randomProperty": "foobar", "title": "This is event 1"}'>My Event 1</div>

样品 https://jsfiddle.net/5wgoodwp/1/

/* Edited from http://fullcalendar.io/js/fullcalendar-2.5.0/demos/external-dragging.html */

HTML

<div id='wrap'>

  <div id='external-events'>
    <h4>Draggable Events</h4>
    <div class='fc-event' data-event='{"id": 1, "randomProperty": "foobar", "title": "This is event 1"}'>My Event 1</div>
  </div>

  <div id='calendar'></div>

  <div style='clear:both'></div>

</div>

JS

/* initialize the external events
        -----------------------------------------------------------------*/

$('#external-events .fc-event').each(function() {

  // make the event draggable using jQuery UI
  $(this).draggable({
    zIndex: 999,
    revert: true, // will cause the event to go back to its
    revertDuration: 0 //  original position after the drag
  });

});


/* initialize the calendar
-----------------------------------------------------------------*/

$('#calendar').fullCalendar({
  header: {
    left: 'prev,next today',
    center: 'title',
    right: 'month,agendaWeek,agendaDay'
  },
  editable: true,
  droppable: true, // this allows things to be dropped onto the calendar
  drop: function() {
    $(this).remove();
  },
  eventReceive: function(event) {
    alert(JSON.stringify(event, null, 4));
  }
});