如何在Angular js日历中添加单个事件?

时间:2018-09-06 14:54:12

标签: javascript angular calendar

我对角度JS非常陌生。最终,我找到了一个不错的日历,多数民众赞成附带一个创建随机事件的事件。

现在我想知道如何添加一个事件。

这是JS:

angular.module('downtimeCalendarApp', ['ui.rCalendar']);

angular.module('downtimeCalendarApp').controller    ('CalendarCtrl', ['$scope', function ($scope) {
 'use strict'; 
  $scope.changeMode = function (mode) { 
      $scope.mode = mode; 
  }; 


  $scope.today = function () { 
      $scope.currentDate = new Date(); 
  }; 


  $scope.isToday = function () { 
      var today = new Date(), 
          currentCalendarDate = new Date($scope.currentDate); 


      today.setHours(0, 0, 0, 0); 
      currentCalendarDate.setHours(0, 0, 0, 0); 
      return today.getTime() === currentCalendarDate.getTime(); 
  }; 


  $scope.loadEvents = function () { 
      $scope.eventSource = createRandomEvents(); 
  }; 


  $scope.onEventSelected = function (event) { 
      $scope.event = event; 
  }; 



  $scope.onTimeSelected = function (selectedTime, events) { 
      console.log('Selected time: ' + selectedTime + ' hasEvents: ' + (events !== undefined && events.length !== 0)); 
 }; 


function createRandomEvents() { 
   var events = []; 
     for (var i = 0; i < 50; i += 1) { 
          var date = new Date(); 
          var eventType = Math.floor(Math.random() * 2); 
          var startDay = Math.floor(Math.random() * 90) - 45; 
          var endDay = Math.floor(Math.random() * 2) + startDay; 
          var startTime; 
          var endTime; 
          if (eventType === 0) { 
             startTime = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() + startDay)); 
              if (endDay === startDay) { 
                  endDay += 1; 
              } 
              endTime = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() + endDay)); 
              events.push({ 
                  title: 'Planned Maintenance: Mercedes PRO connect Store', 
                  startTime: startTime, 
                  endTime: endTime, 
                  allDay: true 
              }); 
          } else { 
              var startMinute = Math.floor(Math.random() * 24 * 60); 
              var endMinute = Math.floor(Math.random() * 180) + startMinute; 
              startTime = new Date(date.getFullYear(), date.getMonth(), date.getDate() + startDay, 0, date.getMinutes() + startMinute); 
             endTime = new Date(date.getFullYear(), date.getMonth(), date.getDate() + endDay, 0, date.getMinutes() + endMinute); 
             events.push({ 
                  title: 'Downtime: #48834734994 Mercedes me connect', 
                  startTime: startTime, 
                  endTime: endTime, 
                  description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum',
                  allDay: false 
              }); 
          } 
      } 
      return events; 

}

所以我想删除随机事件部分并以这种格式创建单个事件,就像我在其他JS中为票证所做的那样。

  $scope.tickets = [
  {
   'startTime: 'xxxxx',
   'endTime': 'xxxxx',
   'title': 'xxxxx',
    and more...
  }

];

有人可以帮助我,并在上面的日历脚本中告诉您在哪里进行更改。或逐步指导我

谢谢!

0 个答案:

没有答案