Javascript 通过角度引导日历将Json中的日期参数作为事件传递

Javascript 通过角度引导日历将Json中的日期参数作为事件传递,javascript,php,angularjs,json,Javascript,Php,Angularjs,Json,我正在使用创建事件日历,其想法是将事件存储在数据库中。无论如何,为了获取事件,我使用PHP从MySQL数据库获取数据,并使用JSON格式将它们直接发送到日历的控制器,如下所示: $date = $row['date_activity']; $start = $row['starthour']; $start_date = date('D M d Y H:i:s O',strtotime("$date $start")); $end = $row['endhour

我正在使用创建事件日历,其想法是将事件存储在数据库中。无论如何,为了获取事件,我使用PHP从MySQL数据库获取数据,并使用JSON格式将它们直接发送到日历的控制器,如下所示:

    $date = $row['date_activity']; 
    $start = $row['starthour'];
    $start_date = date('D M d Y H:i:s O',strtotime("$date $start"));
    $end = $row['endhour'];
    $end_date = date('D M d Y H:i:s O',strtotime("$date $end"));
    $acttitle = $row['title_activity'];  

    $arr[] = array('startsAt' => $start_date,
    'endsAt'=>$end_date,
    'title'=>$acttitle,
    'type'=>'warning');
并在控制器中使用以下命令调用:

    viewControllers.controller('calendarioController',['$scope','$http','$stateParams', function($scope, $http, moment, alert) {

    $scope.calendarView = 'month';
    $scope.viewDate = new Date();
    $http.get('activities.php').success(function(output){
       $scope.placeholder = output;
       console.log($scope.placeholder);
       });
    }]);
控制台日志显示了具有适当内容的对象,但当我尝试调用日历上的事件时,它告诉我日期不是Javascript格式,并且不起作用。是否有一种方法可以存储来自http.get的结果,然后在控制器定义中创建一个事件数组? 仅供参考,这是使用角度引导日历的事件格式

    $scope.events = [
      {
      title: 'My event title', // The title of the event
      type: 'info', // The type of the event (determines its color). Can be important, warning, info, inverse, success or special
      startsAt: new Date(2013,5,1,1), // A javascript date object for when the event starts
      endsAt: new Date(2014,8,26,15), // Optional - a javascript date object for when the event ends
editable: false, // If edit-event-html is set and this field is explicitly set to false then dont make it editable.
      deletable: false, // If delete-event-html is set and this field is explicitly set to false then dont make it deleteable
      draggable: true, //Allow an event to be dragged and dropped
      resizable: true, //Allow an event to be resizable
      incrementsBadgeTotal: true, //If set to false then will not count towards the badge total amount on the month and year view
      recursOn: 'year', // If set the event will recur on the given period. Valid values are year or month
      cssClass: 'a-css-class-name' //A CSS class (or more, just separate with spaces) that will be added to the event when it is displayed on each view. Useful for marking an event as selected / active etc
    }
    ];

我通过覆盖控制器中的$scope.event[]atribute找到了解决方法:

    $scope.events = output;
       console.log($scope.events);
       for (var i = 0; i < $scope.events.length; i++) {
           $scope.events[i].startsAt = new Date($scope.events[i].startsAt);
           $scope.events[i].endsAt = new Date($scope.events[i].endsAt);

    }
$scope.events=输出;
log($scope.events);
对于(变量i=0;i<$scope.events.length;i++){
$scope.events[i].startsAt=新日期($scope.events[i].startsAt);
$scope.events[i].endsAt=新日期($scope.events[i].endsAt);
}