fullcalendar无法管理删除日历中的最后一个事件

时间:2015-10-07 11:36:30

标签: javascript jquery fullcalendar

我正在使用fullcalendar http://fullcalendar.io/ 用户可以在日历中创建和删除事件。有关事件的相关信息将作为JSON在隐藏字段中发送。这在用户创建事件时有效,但我没有设法在用户删除事件时正确更新隐藏字段。这是我的buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:1.3.0' } } apply plugin: 'android' dependencies { compile fileTree(dir: 'libs', include: '*.jar') } android { compileSdkVersion 23 buildToolsVersion "21.1.1" useLibrary 'org.apache.http.legacy' compileOptions.encoding = 'windows-1251' // write your encoding here sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/'] } // Move the tests to tests/java, tests/res, etc... instrumentTest.setRoot('tests') // Move the build types to build-types/<type> // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... // This moves them out of them default location under src/<type>/... which would // conflict with src/ being used by the main source set. // Adding new build types or product flavors should be accompanied // by a similar customization. debug.setRoot('build-types/debug') release.setRoot('build-types/release') } }

的eventclick回调
$('#calendar').fullCalendar

当array_all_events中有多个哈希时,脚本实际上有效,但是当array_all_events为空时,我无法让它将eventClick: function(event, element) { if(confirm('Voulez-vous supprimer cette dispo?')) { $('#calendar').fullCalendar('removeEvents', event._id); var array_all_events = []; var all_events = $('#calendar').fullCalendar('clientEvents'); // console.log(all_events); $.each(all_events, function(index, value) { // console.log(value.start["_d"]); // console.log(index); var day = moment(value.start["_d"]).format('dddd'); var start_time = moment(value.start["_d"]).format("HH:mm"); var end_time = moment(value.end["_d"]).format("HH:mm"); // var id = value.unique_id["_i"]; var slot = { day: day, start_time: start_time, end_time: end_time, }; array_all_events.push(slot); console.log(array_all_events.length); if (array_all_events.length == 0) { $("#dispo_array").val(""); } else { $("#dispo_array").val(JSON.stringify(array_all_events)); } }); } }, 更新为空字符串。

1 个答案:

答案 0 :(得分:0)

我通过从每个循环中获取if和else语句来实现它。

  eventClick: function(event, element) {
      if(confirm('Supprimer cette disponibilité?')) {

        $('#calendar').fullCalendar('removeEvents', event._id);
        var array_all_events = [];
        var all_events = $('#calendar').fullCalendar('clientEvents');
        // console.log(all_events);
        $.each(all_events, function(index, value) {
          // console.log(value.start["_d"]);
          // console.log(index);
           var day         = moment(value.start["_d"]).format('dddd');
           var start_time  = moment(value.start["_d"]).format("HH:mm");
           var end_time    = moment(value.end["_d"]).format("HH:mm");
             // var id          = value.unique_id["_i"];
             var slot        = {
                day: day,
                start_time: start_time,
                end_time: end_time,
              };
            array_all_events.push(slot);
            // console.log(array_all_events.length);
        });
       if (array_all_events.length == 0) {
          console.log("hello");
          $("#dispo_array").val("");
        }
        else {
          console.log(typeof(array_all_events));
          console.log(array_all_events.length);
          $("#dispo_array").val(JSON.stringify(array_all_events));
        }
      }
    },