我遇到了来自http请求的数据问题,以便向由fullcalendar(calendar.js)提供支持的指令模型提供数据
首先是我的代码。
HTML
<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>
CONTROLLER
myApp.controller('ScheduleController', ['$scope', '$http', '$compile', 'uiCalendarConfig', function ($scope, $http, $compile, uiCalendarConfig) {
$scope.uiConfig = {
calendar: {
droppable: true,
selectable: true,
selectHelper: true,
editable: true,
height: 'auto',
header: {
left: 'title',
center: '',
right: 'today prev,next'
},
}
}
$scope.getRequestStatus = function(){
return $http({
method : "GET",
url : "myUrl"
}).then(function success(response) {
var request_details = [];
for(var i = 0; i < response.data.length; i++){
request_details[i] = {};
request_details[i].id = response.data[i]['request_id'];
request_details[i].title = response.data[i]['request_id'];
request_details[i].start = new Date(response.data[i]['start']);
request_details[i].end = new Date(response.data[i]['end']);
}
return request_details;
}, function error(response) {
return response.statusText;
});
}
$scope.getRequestStatus().then(function(requestStatus){
$scope.eventSources = [$scope.events];
})
}
注意:我可以获取数据,但它不会从日历中显示。
$scope.getRequestStatus().then(function(requestStatus){
$scope.eventSources = [$scope.events];
})
然而,当我像下面的示例一样手动完成事件时,它可以正常工作。
$scope.events = [
{title: 'All Day Event',start: new Date()},
];
$scope.eventSources = [$scope.events];
来自http和手册的数据都是相同的。
我还尝试使用$ timeout延迟请求,但该项目未显示
答案 0 :(得分:0)
尝试改变:
$ scope.getRequestStatus = function(){ return $ http({ 方法:“GET”, 网址:“myUrl” 然后(函数成功(响应){
var request_details = [];
for(var i = 0; i < response.data.length; i++){
request_details[i] = {};
request_details[i].id = response.data[i]['request_id'];
request_details[i].title = response.data[i]['request_id'];
request_details[i].start = new Date(response.data[i]['start']);
request_details[i].end = new Date(response.data[i]['end']);
}
return request_details;
}, function error(response) {
return response.statusText;
});
}
到
var getRequestStatus = function(){
return $http({
method : "GET",
url : "myUrl"
}).then(function success(response) {
var request_details = [];
for(var i = 0; i < response.data.length; i++){
details = {};
details.id = response.data[i]['request_id'];
details.title = response.data[i]['request_id'];
details.start = new Date(response.data[i]['start']);
details.end = new Date(response.data[i]['end']);
request_details.push(details);
}
return request_details;
}, function error(response) {
return response.statusText;
});
}
答案 1 :(得分:0)
我已经解决了这个问题。只需将boolean parent放在你的指令html上,然后在数据准备就绪时显示它。见下面的例子:
<强> TEMPLATE 强>
from random import sample
def split(n, k):
splits = [0] + sorted(sample(range(1, n), k-1)) + [n]
return [end-start for start, end in zip(splits, splits[1:])]
>>> split(10, 7)
[1, 3, 1, 1, 1, 1, 2]
>>> split(10, 7)
[1, 1, 1, 1, 1, 4, 1]
>>> split(10, 7)
[1, 2, 2, 1, 2, 1, 1]
>>> split(100, 12)
[10, 10, 8, 5, 7, 15, 1, 5, 1, 8, 26, 4]
<强> CONTROLLER 强>
<div ng-if="ready">
<div ui-calendar="uiConfig.calendar" ng-model="eventSource"></div>
</div>