2014-12-27 69 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> 

希望这有助于。