php - 在 .then() 函数内尝试 angular.forEach 时出错

标签 php mysql angularjs datepicker

我从我的 angularJs 工厂、我的 php server-mysql 后端正确接收到了这个漂亮的 json 数组。这是一个有开始日期的约会:

   [{"id":"1","title":"Loi Travail","infos":null,
     "adresse":"12 avenue des lis 78013  paris",
     "criticite":"4","fichiers":null,
     "start":"2017-06-11T22:37:59.012Z"},
    {"id":"17","title":"jjtyjyjt","infos":"jytjjyjyj",
     "adresse":"tjtyjjyj","criticite":"7","fichiers":"",
     "start":"2017-06-11T22:37:59.012Z"}]

问题是 angular-material-datetimepicker 无法识别开始日期,因为它是一个字符串,所以我需要执行一个循环来添加 new Date(),用于转换每个我的“开始”元素。

所以,我已经完成了这个简短的代码:

rdvFactory.get_rdvs().then(function(data){ 
    console.log(data.data);

    angular.forEach(data.data),function(value,index){
        console.log(value.start); 
    }
}).finally(function(){}) 

但是我的 console.log 没有显示任何内容,而是出现了这个奇怪错误:

TypeError: b is undefined Trace de la pile : q@https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:7:481 @http://localhost/rdvjuristes/app.js:61:2 h/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:134:467 $digest@https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:145:417 $apply@https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:149:111 l@https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:102:87 wg/https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:107:489 Possibly unhandled rejection: {}

你认为这与 $q 的事情有关吗?也许还有另一种方法来转换日期?

如果您有想法,非常感谢,祝您有美好的一天。

仅供引用,如果我输入此内容,那么日历会很好地显示 rendez -vous(请查看 new Date()):

$scope.events = [{"id":"1","title":"Loi Travail","infos":null,
                  "adresse":"12 avenue des lis 78013  paris",
                  "criticite":"4","fichiers":null,
                  "start":new Date("2017-06-11T22:37:59.012Z")}] 

最佳答案

根据docs ,改变

来自

 angular.forEach(data.data),function(value,index){
        console.log(value.start); 
}

 angular.forEach(data.data,function(value,index){
        console.log(value.start); 
 });

关于php - 在 .then() 函数内尝试 angular.forEach 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44489572/

相关文章:

Arch-Linux/arm 上的 C++ MySQL 连接器

angularjs - 如何在 angularjs 中使用 ngFor

php - 带有 PDO 下拉列表的 undefined variable

php - 一般错误 2014 在 closeCursor() 之后仍然发生

php - 在 PHP 中解析时需要在 JSON feed 中保留反斜杠

jquery - Google Places Photos API 以什么格式返回图像?

javascript - 使用 AngularJS 快速 session

php - WordPress 分页无法正常工作

php - 如何将图像放在 3 x 3 的 table 上?

mysql限制为每个组返回的行数