1

这太疯狂了,我不知道为什么!?

这是我的问题:

当我登录时calEvent.start,我会在正确的时间得到正确的日期,但是!当我记录 obj 时calEvent,我的开始日期不显示时间:(。

我愿意:

console.log('=======addNewEvent=========');
console.log('log of calEvent.start : ' + calEvent.start);
console.log('log of calEvent obj : ');
console.dir(calEvent);
console.log('========================');

这就是我得到的:

控制台.log(calEvent.start)

Fri Oct 25 2013 12:30:00 GMT-0400 (EDT) 

控制台日志(calEvent)

Object
    date: "2013-10-25"
    date_end: "2013-10-25"
    date_end_hour: "6:30 pm"
    date_start_hour: "5:30 pm"
    end: Fri Oct 25 2013 18:30:00 GMT-0400 (EDT)
    end_date: "2013-10-25"
    end_time: "18:30"
    id: 109
    location: "63"
    presettype: null
    repeat_type: "N"
    start: Fri Oct 25 2013 00:00:00 GMT-0400 (EDT)
    start_date: "2013-10-25"
    start_time: "17:30"
    time_zone: 4
    title: "s"
    type: "C"
    typeClass: "class"
    user_locations: null
    zipcode: "10023"

如您所见,calEvent.start显示正确的时间12:30:00calEvent将时间显示为00:00:00

知道为什么会这样吗?:(

注意:对不起我的英语*

========================= [设置calEvent.start的代码] ================ =========

eventSetEvent : function(calEvent, $event, $titleName, $typeName, $typeL) {           
 resetForm($dialogContent);

 $dialogContent.dialog({
    modal: true,
    title: $titleName,
    open: function() {
        $(".j-start-time").timepicker('setTime',  MAIN.calendar.from24To12(MAIN.calendar.getInfoFromDate().hours(calEvent.start) + ':'+ MAIN.calendar.getInfoFromDate().minutes(calEvent.start)) );
        $(".j-end-time").timepicker('setTime',  MAIN.calendar.from24To12(MAIN.calendar.getInfoFromDate().hours(calEvent.end) + ':'+ MAIN.calendar.getInfoFromDate().minutes(calEvent.end)) );
    },
    close: function() {
       $dialogContent.dialog("destroy");
       $('#calendar').weekCalendar("removeUnsavedEvents");
    },
    buttons: {
       save : function() {
            var x = new Date();
                time_zone = x.getTimezoneOffset() / 60;

            calEvent.id = id;
            id++;

            MAIN.calendar.validation();

            if( $typeL == 'C') {
                calEvent.typeClass = 'class';
            } 

            if( $typeL == 'P') {
                calEvent.typeClass = 'private';
            }

            if( $typeL == 'O') {
                calEvent.typeClass = 'available';
            }

            if( $('.error-field').doesExist() ) {
                $('.j-err-msg').fadeIn();
            } else {
                $('.j-err-msg').fadeOut();

                calEvent.date = MAIN.calendar.getInfoFromDate().year(calEvent.start) + '-' + MAIN.calendar.getInfoFromDate().month(calEvent.start) + '-' + MAIN.calendar.getInfoFromDate().day(calEvent.start);
                calEvent.date_end = $('.j-date').val() != '' ? $('.j-date').val() : MAIN.calendar.getInfoFromDate().year(calEvent.start) + '-' + MAIN.calendar.getInfoFromDate().month(calEvent.start) + '-' + MAIN.calendar.getInfoFromDate().day(calEvent.start);
                calEvent.date_end_hour = $('.j-end-time').val().toLowerCase();
                calEvent.date_start_hour = $('.j-start-time').val().toLowerCase();
                calEvent.end_date = $('.j-date').val() != '' ? $('.j-date').val() : MAIN.calendar.getInfoFromDate().year(calEvent.start) + '-' + MAIN.calendar.getInfoFromDate().month(calEvent.start) + '-' + MAIN.calendar.getInfoFromDate().day(calEvent.start);
                calEvent.end_time = MAIN.calendar.getInfoFromDate().hours(calEvent.end) + ':' + MAIN.calendar.getInfoFromDate().minutes(calEvent.end);
                calEvent.presettype = null;
                calEvent.repeat_type = $('.j-radio-repeat:checked').val();
                calEvent.start_date = MAIN.calendar.getInfoFromDate().year(calEvent.start) + '-' + MAIN.calendar.getInfoFromDate().month(calEvent.start) + '-' + MAIN.calendar.getInfoFromDate().day(calEvent.start);
                calEvent.start_time = MAIN.calendar.getInfoFromDate().hours(calEvent.start) + ':' + MAIN.calendar.getInfoFromDate().minutes(calEvent.start);
                calEvent.time_zone = time_zone;
                calEvent.title =  $('.j-title').val() ;
                calEvent.type = $typeL;
                calEvent.user_locations = null;
                calEvent.zipcode = $('.j-zipcode').val();

                MAIN.calendar.addNewEvent(calEvent);
                $calendar.weekCalendar("removeUnsavedEvents");
                $calendar.weekCalendar("updateEvent", calEvent);
                $(".ui-dialog-content").dialog("close");                            
            }
       },
       cancel : function() {
          $(".ui-dialog-content").dialog("close");
       }
    }
 }).show();

 $dialogContent.find(".date_holder").text($calendar.weekCalendar("formatDate", calEvent.start));
},
4

1 回答 1

2

我怀疑你被 JavaScript 控制台欺骗了。

当您 logcalEvent.start时,它会记录当时该属性的实际值。

当您只是 logcalEvent时,它只显示一行,对吗?然后单击小箭头以展开对象列表,对吗?

然后发生的事情是调试器在您展开calEvent对象时获取对象的属性,而不是在您第一次调用时。console.log(calEvent)

当我有你的时候,让我们谈谈如何让你的代码更简单。我只举一个例子:冗长的函数调用在这个函数中MAIN.calendar.getInfoFromDate()出现了20 次。

除非有特定的理由这样做,否则你应该调用一次函数,将其返回值保存在一个变量中,然后在这 20 个地方使用该变量:

eventSetEvent : function(calEvent, $event, $titleName, $typeName, $typeL) {           
 resetForm($dialogContent);
 var info = MAIN.calendar.getInfoFromDate();

 $dialogContent.dialog({
    modal: true,
    title: $titleName,
    open: function() {
        $(".j-start-time").timepicker('setTime',  MAIN.calendar.from24To12(info.hours(calEvent.start) + ':'+ info.minutes(calEvent.start)) );
        $(".j-end-time").timepicker('setTime',  MAIN.calendar.from24To12(info.hours(calEvent.end) + ':'+ info.minutes(calEvent.end)) );
    },
    close: function() {
       $dialogContent.dialog("destroy");
       $('#calendar').weekCalendar("removeUnsavedEvents");
    },
    buttons: {
       save : function() {
            var x = new Date();
                time_zone = x.getTimezoneOffset() / 60;

            calEvent.id = id;
            id++;

            MAIN.calendar.validation();

            if( $typeL == 'C') {
                calEvent.typeClass = 'class';
            } 

            if( $typeL == 'P') {
                calEvent.typeClass = 'private';
            }

            if( $typeL == 'O') {
                calEvent.typeClass = 'available';
            }

            if( $('.error-field').doesExist() ) {
                $('.j-err-msg').fadeIn();
            } else {
                $('.j-err-msg').fadeOut();

                calEvent.date = info.year(calEvent.start) + '-' + info.month(calEvent.start) + '-' + info.day(calEvent.start);
                calEvent.date_end = $('.j-date').val() != '' ? $('.j-date').val() : info.year(calEvent.start) + '-' + info.month(calEvent.start) + '-' + info.day(calEvent.start);
                calEvent.date_end_hour = $('.j-end-time').val().toLowerCase();
                calEvent.date_start_hour = $('.j-start-time').val().toLowerCase();
                calEvent.end_date = $('.j-date').val() != '' ? $('.j-date').val() : info.year(calEvent.start) + '-' + info.month(calEvent.start) + '-' + info.day(calEvent.start);
                calEvent.end_time = info.hours(calEvent.end) + ':' + info.minutes(calEvent.end);
                calEvent.presettype = null;
                calEvent.repeat_type = $('.j-radio-repeat:checked').val();
                calEvent.start_date = info.year(calEvent.start) + '-' + info.month(calEvent.start) + '-' + info.day(calEvent.start);
                calEvent.start_time = info.hours(calEvent.start) + ':' + info.minutes(calEvent.start);
                calEvent.time_zone = time_zone;
                calEvent.title =  $('.j-title').val() ;
                calEvent.type = $typeL;
                calEvent.user_locations = null;
                calEvent.zipcode = $('.j-zipcode').val();

                MAIN.calendar.addNewEvent(calEvent);
                $calendar.weekCalendar("removeUnsavedEvents");
                $calendar.weekCalendar("updateEvent", calEvent);
                $(".ui-dialog-content").dialog("close");                            
            }
       },
       cancel : function() {
          $(".ui-dialog-content").dialog("close");
       }
    }
 }).show();

 $dialogContent.find(".date_holder").text($calendar.weekCalendar("formatDate", calEvent.start));
},

您可以进行其他简化,但这将为您提供一个起点。

于 2013-10-24T22:52:32.633 回答