4

我想根據說明設置日曆。日曆本身顯示在頁面上,但不顯示任何事件。AngularJS ui-calendar - 模型與事件

代碼模板:

<div ui-calendar ng-model="eventSources">

代碼在我的控制器:

var date = new Date(); 
var d = date.getDate(); 
var m = date.getMonth(); 
var y = date.getFullYear(); 

$scope.eventSources = [ 
    { 
    "title": 'All Day Event', 
    "start": new Date(y, m, d)}, 
{ 
    "title": 'Long Event', 
    "start": new Date(y, m, d - 5), 
    "end": new Date(y, m, d - 2)}]; 

當我通過eventSources循環模板它的工作原理:

<li ng-repeat="e in eventSources"> 
    {{e.title}} {{e.start}} 
</li> 

日曆沒有按儘管如此,我什麼也沒有展示。控制檯中也沒有錯誤。你們有沒有對這裏發生的事情有所瞭解的想法?

回答

8

使用只需一組事件是這裏的問題。 uiCalendar只接收一個eventSources數組。 http://arshaw.com/fullcalendar/docs/event_data/eventSources/

我相信我們應該讓它足夠靈活,以允許所有的api來源。

+0

沒錯。非常感謝! –

+0

哇!這是堅果!在黑暗中捅了我半天以上,因爲文件清楚地表明他們接受Arshaw接受的任何內容。我嘗試了Arshaw文檔(原始數組,eventSources對象)中列出的所有可能的格式 - 但無法想到eventSources對象的「數組」。哇哇!先生,你是一個天才。 – Ruslan

0

這是我如何加載使用「eventsources:」事件我有eventsources數組: 您有2種方法可以做到這一點:

1- JSON(更快,因爲事件已經JSON格式無需迭代) 2- Ajax調用(慢,因爲你必須遍歷這裏的XML)

var othersources = {  
        jsonsource: {    
            url: ajaxcallURL(_url,"7"), 
            type: 'POST',        
            //error: function() { alert('something broke with courses...'); }, 
            data:{                 
             'func':func, 
             'year':y 
            }, 
            cache: false,    
            color: '#C1272D', 
            textColor: 'white'        
           }, 
        ajaxcallsource: {    
          events: function(start, end, callback) { 
          $.ajax({ 
           type: 'POST', 
           url: ajaxcallURL(_url,"7"),    
           data: { 
            // our hypothetical feed requires UNIX timestamps 
            start: Math.round(start.getTime()/1000), 
            end: Math.round(end.getTime()/1000),         
            'func':func, 
            'year':y      
           },   
           success: function(doc) {  

            var events = []; 
            var allday = null; //Workaround 
            var Editable = null; //Workaround 
            $(doc).find('event').each(function() 
            {      
             if($(this).attr('allDay') == "false") //Workaround 
               allday = false; //Workaround 
             if($(this).attr('allDay') == "true") //Workaround 
               allday = true; //Workaround 
             if($(this).attr('editable') == "false") //Workaround 
               Editable = false; //Workaround 
             if($(this).attr('editable') == "true") //Workaround 
               Editable = true; //Workaround      

             events.push({ 
              id: $(this).attr('id'), 
              title: $(this).attr('title'), 
              start: $(this).attr('start'), 
              end: $(this).attr('end'),      
              allDay: allday, 
              editable: Editable 
             });        
            });            
            callback(events); 
           } 
          });    
         },     
          cache: false, 
          //error: function() { alert('something broke with courses...'); }, 
          color: '#C1272D', 
          textColor: 'white', 
          //className: 'course' 
         } 
    } //othersources array close 

裏面的日曆屬性:

eventSources:[othersources.jsonsource,ajaxcallsource], 

好運

+0

是的,我的錯誤是我有一系列事件,而不是事件源。 –