2014-12-27 70 views
0

我正在嘗試在Angular Js應用中使用angular-ui/ui-calendar(FullCalendar)。 我有選擇框列出了一些項目,根據選定的項目,我的事件源URL需要更新。因此,在控制器中,我會更新它,但是日曆仍然沒有使用更新後的URL,並且一旦源發生更改,我還需要日曆刷新/渲染。 按照這link需要一些刪除和添加事件源。 我對Jquery和Angular都很陌生,所以我會很感激,如果任何人都可以解釋我如何在角js中做到這一點。angular-ui/ui-calendar在Angular JS中渲染後更改事件源

我的控制器的一些位置,我設置了url源,但我認爲這不是正確的方法,它也不起作用。

$scope.locationId = 0 
$scope.url = "./api/ev/event/calendarByLocationId?locationId=" + $scope.locationId; 
$scope.eventSource = { 
     url : $scope.url 
    }; 

$scope.setURL = function(locationId) { 
    $scope.locationId = locationId 
    $scope.url = "./api/ev/event/calendarByLocationId?locationId=" + $scope.locationId; 
    $scope.eventSource = { 
     url : $scope.url 
    }; 
    $scope.eventSources = [ $scope.eventSource ]; 
} 

回答

2

沒有使用refetchEvents,下面的代碼適用於我。添加新事件源後,日曆會自動從新源中獲取新數據。

// This function is called to change the event source. When 
// ever user selects some source in the UI 
$scope.setEventSource = function(locationId) { 
// remove the event source. 
uiCalendarConfig.calendars['myCalendar'].fullCalendar('removeEventSource', $scope.eventSource); 
// Create the new event source url 
$scope.eventSource = {url : "./api/ev/event/calendarByLocationId?locationId=" + locationId}; 
// add the new event source. 
uiCalendarConfig.calendars['myCalendar'].fullCalendar('addEventSource', $scope.eventSource); 
} 
1

我想清楚添加和刪除事件源。似乎有一個問題。

但暫時,我有一個REST網址。一旦更新,數據就會更新。那時我通過觸發這個程序讓程序在同一個網址刷新事件。這使url可以刷新並從數據庫中再次抓取。

$scope.myCalendar.fullCalendar('refetchEvents'); 

哪個HTML代碼應該是這樣的:

<div class="calendar" ng-model="eventSources" calendar="myCalendar" config="uiConfig.calendar" ui-calendar="uiConfig.calendar"></div> 

希望這有助於。