2015-11-02 96 views
0

我正在使用角度js fullcalendar control.I調用服務器方法,該方法返回日期我想在服務器的響應fullcalendar中設置日期方法。如何在角度js fullcalendar中設置日期在ajax響應

我正在使用ajax進行服務器調用。

這裏是我指的代碼:

myModule.controller('calendarController', ['$scope', '$timeout', function ($scope, $timeout) { 
    var date = new Date(); 
    var d = date.getDate(); 
    var m = date.getMonth(); 
    var y = date.getFullYear(); 
    // '1/25/2015 12:00:00 AM' AND dDueDate <= '3/8/2015 12:00:00 AM' 
    var GetEventData = { 
    startDate: "1/25/2008 12:00:00 AM", 
    endDate: "3/8/2016 12:00:00 AM", 
    tabstate: "Org" 
    }; 
    var url = window.opener.oT.TracerURL + "/DakotaScheduler.aspx/GetEventData"; 
    $.ajax({ 
    url: url, 
    type: 'POST', 
    data: JSON.stringify(GetEventData), 
    contentType: "application/json; charset=utf-8", 
    dataType: "json" 
    }).done(function (response) { 
    var eventdate = response.d.EventDataTable[0].EventDate; 
    $scope.events = [{ 
     title: 'test', 
     start: new Date(y, m, d, 3, 0), 
     end: new Date(y, m, d, 4, 0) 
    }]; 

    $scope.eventSources = [$scope.events]; 

    }).fail(function (jqXHR, textStatus, errorThrown) { 
    console.log(errorThrown); 
    }); 
    $scope.events = [{ 
     title: 'test', 
     start: new Date(y, m, d, 3, 0), 
     end: new Date(y, m, d, 4, 0) 
    }]; 
    $scope.eventSources = [$scope.events]; 
}]); 

正在發生的事情在這個例子中

$scope.eventSources = [$scope.events]; 

線,裏面是Ajax調用的完成部分代碼沒有設定日期,但外部代碼正在按預期工作。

但我需要從服務器返回的日期值應設置。

+0

爲什麼您使用AJAX,而不是$ http服務? – Jax

回答

0

試試這個

$timeout(function() { 
    $scope.eventSources = [$scope.events]; 
}, 0); 
+0

我曾嘗試使用設置超時,但它仍然無法正常工作。 – user2243331

相關問題