自定义dateFilter在iOS设备中返回`undefined NaN`&仅限模拟器

时间:2016-01-23 20:24:15

标签: javascript ios date ionic-framework timestamp

我的离子应用程序中有一个自定义日期过滤器,可以按日期对事件进行分组,并将它们放在手风琴下拉菜单中。

controller.js

.filter('customDateFilter', function() {
  return function(input) {
    var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'Novemeber', 'December'];
    var weekdays = ['SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY'];
    var inputDate = new Date(input);

return weekdays[inputDate.getDay()] + ", " + months[inputDate.getMonth()] + ", " + inputDate.getDate();   

}; })

我在我的服务中获得了具有此功能的群组中的事件:

  function setBookingGroupDate(bookings) {
    //*2*Go through each booking
    for (var i = bookings.length - 1; i >= 0; i--) {
      var date = new Date(bookings[i].driver_departing_time); //*3*Create date from drvier_departing_date
      var dateWithoutHour = new Date(date.getFullYear(), date.getMonth(), date.getDate()); //*4* create same date but w/o the hr to minimize the differences
      var dateCode = dateWithoutHour.getTime(); //Get timeStamps to have same filed for all and same type to be able to order and GROUP
      bookings[i].groupByDateCode = dateCode; //add it back to respective booking[index]
    };
    //Return the bookings
    return bookings;
  }

我会在我的视图中显示它们;

<ion-item ng-repeat="(date, groupedBooking) in bookings | orderBy: 'groupByDateCode' | groupBy: 'groupByDateCode'"> <!-- bookingService.js line 15 -23 -->
  <ion-item class="item-stable"
    ng-click="toggleGroup(groupedBooking)"
    ng-class="{active: isGroupShown(groupedBooking)}">
    <i class="today-icon-sytles" ng-class="isGroupShown(groupedBooking) ? 'ion-ios-minus' : 'ion-ios-plus'"></i>
    &nbsp;
    <!--Displays the date in our format  and the number of bookings per date-->

    <span id="dates-fonts-styles">{{groupedBooking[0].driver_departing_time | customDateFilter}}</span>

    <div class="bookings-badge">{{ groupedBooking.length }}</div>

  </ion-item>

所有内容都显示我想要的方式,但只能在浏览器和Android设备上显示。这不适用于iOS模拟器和设备..而不是向我显示我的日期很好地显示它返回

undefiend NaN:没有错误。

我正在查看此示例[https://github.com/angular/angular.js/issues/3334][1]但我不太清楚在现有代码中应该在哪里执行重构。

在此之前有没有人有这个问题可以提供解决方案?谢谢!

0 个答案:

没有答案