[英]FullCalendar - removing event via modal
我正在使用FullCalendar,並且在嘗試刪除事件時被卡住。 這是交易:當我單擊一個事件時,它會帶給我一個模態,其中包含我對該事件的所有信息,在此模態中,我有2個按鈕:一個接受事件,一個拒絕事件。 我需要的是,當我單擊“接受”時,事件顏色必須變為綠色,而當我拒絕事件時,必須將其刪除。 我怎樣才能做到這一點? 這是我的代碼:
CalendarioAgenda.html(我的模態所在,我減少了代碼,使它更易於理解,但是我擁有的每個字段都像#ModalCliente):
<div class="modal fade" id="ModalVistoria" tabindex="-1" role="basic" aria-hidden="true" style="display: none">
<div class="modal-dialog" style="width:50%">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title"></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-xs-4">
<div class="form-group form-md-line-input">
<div class="form-control form-control-static" id="ModalCliente">
</div>
<label for="ModalCliente">Cliente</label>
</div>
</div>
</div>
<div class="modal-footer">
<input type="hidden" id="ModalId"/>
<button type="button" class="btn red-intense Recusar">Recusar</button>//button to refuse the event
<button type="button" class="btn blue-steel Aceitar">Aceitar</button>//button to accept the event
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
</div>
還有我的Calendar.js:
$('#calendar').fullCalendar({ //re-initialize the calendar
header: h,
defaultView: 'month', // change default view with available options from http://arshaw.com/fullcalendar/docs/views/Available_Views/
slotMinutes: 15,
editable: true,
droppable: false, // this allows things to be dropped onto the calendar !!!
events: [{
id: '01',
title: 'Vistoria Viceri',
start: new Date(y, m, 1), //usar start no campo de data da modal
backgroundColor: Metronic.getBrandColor('yellow'),
cliente: 'Viceri',
tipo: 'Empresarial Simples',
hora: '12:00',
endereco: 'General Osorio, 61',
bairro: 'Centro',
cidade: 'Jundiai',
estado: 'SP',
contato: 'Marcel Pratte',
telefone: '11 3308 6999',
}, {
id: '02',
title: 'Visita a cliente',
start: new Date(y, m, d - 5),
end: new Date(y, m, d - 3),
backgroundColor: Metronic.getBrandColor('green'),
cliente: 'Maxtel',
tipo: 'Empresarial',
hora: '15:00',
endereco: 'Avenidade Sao Joao',
bairro: 'Ponte Sao Joao',
cidade: 'Jundiai',
estado: 'SP',
contato: 'Marcio',
telefone: '11 45270001',
}, {
id: '03',
title: 'Vistoria Envision',
start: new Date(y, m, d - 3, 16, 0),
allDay: false,
backgroundColor: Metronic.getBrandColor('red'),
cliente: 'Envision',
tipo: 'Empresarial complexa',
hora: '12:36',
endereco: 'Rua da empresa',
bairro: 'Centro',
cidade: 'Sao Paulo',
estado: 'SP',
contato: 'Joaquim',
telefone: '011 995257788',
}],
//opção de click no evento para redirecionar para modal
eventClick: function (event, jsEvent, view) {
$('.modal-title').html(event.title);
$('#ModalCliente').html(event.cliente);
$('#ModalTipo').html(event.tipo);
$('#ModalDataHora').html(event.d + ' - ' + event.hora);
$('#ModalEndereco').html(event.endereco);
$('#ModalBairro').html(event.bairro);
$('#ModalCidade').html(event.cidade);
$('#ModalEstado').html(event.estado);
$('#ModalContato').html(event.contato);
$('#ModalTel').html(event.telefone);
$('#ModalId').html(event.id);
$('#ModalVistoria').modal();
$('.Recusar').click(function (events) {
var id = $('#ModalId').val();
$('#calendar').fullCalendar('removeEvents', id);
$("#calendar").fullCalendar('addEventSource', events);
});
}
});
謝謝
您的行$('#ModalId').html(event.id);
和var id = $('#ModalId').val();
針對兩個不同的元素,因此您無法檢索調用val()
的事件ID。
通過像這樣設置值$('#ModalId').val(event.id);
它工作正常。
這是您可以重新設置事件並更改背景顏色的部分:
$('.Recusar').click(function (events) {
var id = $('#ModalId').val();
$('#calendar').fullCalendar('removeEvents', id);
$("#calendar").fullCalendar('addEventSource', events);
$('#ModalVistoria').modal('hide');
});
$('.Aceitar').click(function (events) {
var id = $('#ModalId').val();
var ev = $("#calendar").fullCalendar('clientEvents', id);
ev[0].backgroundColor = 'green';
$("#calendar").fullCalendar('addEventSource', events);
$('#ModalVistoria').modal('hide');
});
這是一個工作的jsFiddle: 單擊此處
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.