Javascript 正在从eventReceive获取id
我正试图从我的div中获取id属性值并将其放入日历中。我尝试了很多方法,但都没有成功 我创建了以下div:Javascript 正在从eventReceive获取id,javascript,jquery,html,fullcalendar,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>"; vv_lista_servico=vv_li
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>";
vv_lista_servico=vv_lista_servico+“”+item.descr+“”;
准备好后,我有以下html:
<div class="fc-event fc-list draggable ui-draggable ui-draggable-handle" data-event="{"id":"244"}" data-duration="00:30">Test 1</div>
测试1
当我将事件拖到fullcalendar中时,我的标题和持续时间可以在日历上工作并呈现,但id不起作用
我应该如何创建html来工作并获取id
Thank's根据文档,事件数据需要是有效的JSON,因此在数据事件中使用双引号:
<div class='fc-event' data-event='{"id": 1, "randomProperty": "foobar", "title": "This is event 1"}'>My Event 1</div>
HTML
data event=“{”id:“244”}”
将变得无效html
。尝试将其作为数据事件=“{id':'244'}”
获取。但是,我不能保证这是一个有效的属性和值…谢谢,但这不是问题…谢谢Smcd,但是,我昨天发现了我的问题,不知道如何解决它。。。我使用jquery+ajax来创建事件,但我在fullcalendar上没有适当的委托,因此,我相信eventReceive没有看到映射的元素,也无法在calendar上正确创建!我试图委托事件接收者获取我创建的新元素,但是,直到现在还没有成功,如果你有任何想法,请告诉我!谢谢我不确定我是否遵循-您是否希望将通过ajax删除的事件发送到您的服务器,然后在保存到服务器端后重新加载该事件?不是真的,但是,我发现我的问题,它与包干扰FullCalendar的功能有关。。。现在一切正常!谢谢你的帮助
/* Edited from http://fullcalendar.io/js/fullcalendar-2.5.0/demos/external-dragging.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>
/* 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));
}
});