javascript - 添加或更新事件后,角度引导日历不会更新视图
问题描述
我正在使用 mattlewis 引导日历。事件显示正确。但是如果我将新事件添加到日历,它会复制其他日期的事件,而不是将事件添加到添加的日期。只有在刷新页面后一切正常。我也尝试了 $scope.$apply。但似乎没有任何效果。
这是我的html
<mwl-calendar events="events" view="calendarView"
view-date="viewDate" view-title="calendarTitle"
on-event-click="eventClicked(calendarEvent)"
on-event-times-changed="eventTimesChanged(calendarEvent);
calendarEvent.startsAt = calendarNewEventStart; calendarEvent.endsAt = calendarNewEventEnd"
cell-is-open="cellIsOpen" day-view-start="06:00"
day-view-end="22:59" day-view-split="30"
cell-modifier="cellModifier(calendarCell)"
on-event-click="eventClicked(calendarEvent)"
cell-auto-open-disabled="true"
on-timespan-click="timespanClicked(calendarDate, calendarCell)">
</mwl-calendar>
控制器.js
$scope.events = [];
$scope.myevents = function(start, end, timezone, callback) {
SalesNotifyService.getAllNotify().then(function(response) {
$scope.allleadnotify = response.data;
console.log($scope.allleadnotify);
var events = [];
angular.forEach($scope.allleadnotify,function(event,key){
var today = new Date();
var notifyDates = new Date(event.notifyDate);
if(event.leadName!=null){
$scope.events.push({
title: event.notifyType,
startsAt : event.notifyDate,
endsAt : event.notifyEndDate,
withoffender: event.leadName,
});
} else {
$scope.events.push({
title: event.notifyType,
startsAt : event.notifyDate,
endsAt : event.notifyEndDate,
withoffender: '',
});
}
});
});
}
现在保存后我像这样调用 $scope.myevents 函数
SalesNotifyService.saveNotify(notify).then(function(response){
$scope.notify = response.data;
$scope.myevents();
});
但即使我调用 myevents 函数,事件也没有正确填充到日历中。如果我已经有事件,那么在添加新事件后,旧事件正在复制和显示。如果我重新加载页面,那么一切都很好。在 html 中,我正在调用 myevents 函数在 ng-init 中。谁能告诉如何在添加事件后正确显示事件而不重新加载页面?
解决方案
也许您需要在再次添加事件之前将 $scope.events 重置为空数组?如果你不这样做,那么每次你调用 $scope.myevents() 你都会在同一个数组中再次添加事件而不删除它们。所以在 $scope.myevents 做 $scope.events=[] 在函数的开头
$scope.events = 事件;并将事件推送到本地“事件”数组中。
推荐阅读
- azure - Kubernetes 无法在 azure 上创建负载均衡器
- python - ValueError:在 groupby 对象上调用 pands value_counts() 时,操作数无法与形状一起广播
- python - 熊猫 - 参数为“1”的持续时间
- html - 在 wordpress 页面上的元素旁边添加一些文本
- c++ - 我可以将某些对象的指针保存在向量中,然后用这些指针调用内联函数吗
- python - 使用滞后的机器学习预测客户流失
- java - 使用 JUnit 5 的 @ParametrizedTest 而不是 @TestFactory Stream 有什么区别/优势
? - css - 如何推迟非批判性风格?
- sql - 使用 Amazon-redshift 提取括号中的数据
- laravel - 仅在刀片中显示特定条件的数据