Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
624 views
in Technique[技术] by (71.8m points)

javascript - Getting id from eventReceive

I'm trying to get the id attribute value from my div and put in calendar. I've tried many ways without success.

I have the following div that I created:

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>";

When ready, I have the following html:

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

When I dragging the event into fullcalendar my title and duration works and render on calendar, but the id does not work.

How I should create my html to work and get the id?

Thank's

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The event data needs to be valid JSON according to eventReceive documentation, so double quotes inside the data-event:

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

Sample 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));
  }
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...