gpt4 book ai didi

javascript - 添加或更新事件后,Angular 引导日历不会更新 View

转载 作者:行者123 更新时间:2023-12-03 01:37:06 25 4
gpt4 key购买 nike

我正在使用 mattlewis bootstrap 日历。事件显示正确。但是,如果我向日历添加新事件,它会复制其他日期中的事件,而不是将事件添加到添加的日期。只有刷新页面后,一切正常 很好。我也尝试了 $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>

Controller.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 中,我是在 ng-init 中调用 myevents 函数。谁能告诉我如何在添加事件后正确显示事件而不重新加载页面?

最佳答案

也许您需要在再次添加事件之前将 $scope.events 重置为空数组?如果您不这样做,那么每次调用 $scope.myevents() 时,您都会在同一数组中再次添加事件,而不删除它们。所以在 $scope.myevents 中,在函数开始处执行 $scope.events=[]

$scope.events = 事件;并将事件推送到本地“events”数组中。

关于javascript - 添加或更新事件后,Angular 引导日历不会更新 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51020037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com