自定义日期.filter不显示在iOS的日期只有.split方法的方法日期、方法、自定义、filter

2023-09-14 00:18:45 作者:娇纵小可爱

我们设法显示我们的应用程序日期的客户希望他们的方式。这对我们来说是一项艰巨的任务,但我们很高兴与结果。我们正在使用离子框架和以下错误出现的仅在iOS 设备和仿真。浏览器和Android完全显示的日期。

We managed to display dates in our app the way the clients wanted them. It was a difficult task for us but we were happy with the result. We are using Ionic Framework and the following ERRORS are appearing ONLY on the iOS devices and Emulators. Browser and Android display the dates perfectly.

所以我一直在这里读书,有些人有运气在 .split 方式。我们补充说,我们的code,但继续得到这个错误,什么是显示NG坏了绑定{{}}。这是从iOS上的误差

SO I've been reading from here that some people had luck with the .split method. We added that to our code but continue getting this error and what displays is broken ng-bind {{}}.. This is the error from iOS

电子R RØR:convDate.split不是一个函数。 (在'convDate.split('')','convDate.split'是不确定的)

**Error: convDate.split is not a function. (In 'convDate.split(' ')', 'convDate.split' is undefined)**
file:///var/mobile/Containers/Bundle/Application/104DE270-18AC-4FB1-9F97-66F93E885A0B/driverApp.app/www/js/controllers/BookingsController.js:147:35
fn
regularInterceptedExpression@file:///var/mobile/Containers/Bundle/Application/104DE270-18AC-4FB1-9F97-66F93E885A0B/driverApp.app/www/lib/ionic/js/ionic.bundle.js:23059:37
expressionInputWatch@file:///var/mobile/Containers/Bundle/Application/104DE270-18AC-4FB1-9F97-66F93E885A0B/driverApp.app/www/lib/ionic/js/ionic.bundle.js:22961:42
$digest@file:///var/mobile/Containers/Bundle/Application/104DE270-18AC-4FB1-9F97-66F93E885A0B/driverApp.app/www/lib/ionic/js/ionic.bundle.js:24507:43
$apply@file:///var/mobile/Containers/Bundle/Application/104DE270-18AC-4FB1-9F97-66F93E885A0B/driverApp.app/www/lib/ionic/js/ionic.bundle.js:24783:31
done@file:///var/mobile/Containers/Bundle/Application/104DE270-18AC-4FB1-9F97-66F93E885A0B/driverApp.app/www/lib/ionic/js/ionic.bundle.js:19196:53
completeRequest@file:///var/mobile/Containers/Bundle/Application/104DE270-18AC-4FB1-9F97-66F93E885A0B/driverApp.app/www/lib/ionic/js/ionic.bundle.js:19368:15
requestLoaded@file:///var/mobile/Containers/Bundle/Application/104DE270-18AC-4FB1-9F97-66F93E885A0B/driverApp.app/www/lib/ionic/js/ionic.bundle.js:19309:24
(anonymous function)console-via-logger.js:172
(anonymous function)ionic.bundle.js:21161
(anonymous function)ionic.bundle.js:17940
$digestionic.bundle.js:24532
$applyionic.bundle.js:24782
doneionic.bundle.js:19195
completeRequestionic.bundle.js:19367
requestLoadedionic.bundle.js:19308

我们的约会FILTER code

  .filter('customDateFilter', function($filter) {
    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 convDate = $filter('date')(new Date(input), 'MMMM dd EEEE yyyy');
    var inputDate = convDate.split(' ');
      // SHOW "Today" on today's date instead of actual date O_o
      var showToday = new Date();

      if (convDate === ($filter('date')(new Date(showToday), 'MMMM dd EEEE yyyy')) return "TODAY";
      if (convDate !== ($filter('date')(new Date(showToday), 'MMMM dd EEEE yyyy')) {
        return inputDate[2] + " " + inputDate[0] + " " + inputDate[1];
      }
    };
  })

的code中的customeDate fiter的看法..

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

函数团体预订我们的。(不知道是否是必要的)

function that groups our bookings.. (not sure if is necessary)

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

这是从这个code返回的日期的周一1月18日等..ONLY的iOS是拍摄我们的错误,并显示{{groupedBooking [0] .driver_departing_time | customDateFilter}}因为是在视图。

The dates that are returned from this code are Monday January 18 and so on.. ONLY iOS is shooting us the error and displaying the {{groupedBooking[0].driver_departing_time | customDateFilter}} as is on the view..

有谁知道,如果有一个工作围绕这个?我们试图.split根据地段好不满的从这里开始。

Does anyone know if there's a work around for this? We tried .split based on lots of good resents from here.

推荐答案

有可以尝试两件事情。如果convDate可以被类型强制转换为字符串,那么你可以尝试

There are two things that can be tried. If convDate can be typecasted to String, then you can try

convDate == showToday

一个双==(而不是三===)为你做一个类型转换。

A double == (instead of triple ===) does a type conversion for you.

或者你也可以尝试通过这convDate转换为字符串

Or you can also try to convert convDate to String by this

convDate = "" + convDate;
 
精彩推荐
图片推荐