我从我的 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/