简体   繁体   English

使用Bootstrap Modal的fullcalendar打开事件

[英]fullcalendar open event using Bootstrap Modal

I'm opening fullcalendar events with bootstrap modal using this example : ( http://www.mikesmithdev.com/blog/fullcalendar-event-details-with-bootstrap-modal/ ) 我使用以下示例使用引导程序模式打开全日历事件:( http://www.mikesmithdev.com/blog/fullcalendar-event-details-with-bootstrap-modal/

It works perfectly. 它运作完美。

Now that the event is opened, I don't know how to go about to retrieve the information of that event. 现在事件已打开,我不知道如何去检索该事件的信息。 Let me explain, the event is linked in my database (mysql) with some other information and other tables. 让我解释一下,该事件在我的数据库(mysql)中与其他一些信息和其他表相关联。 In that modal popup i would like to show linked information. 在该模式弹出窗口中,我想显示链接的信息。

I was thinking that this would work : (in my main page i have this) 我以为这会起作用:(在我的主页上有这个)

element.click(function() {
//set the modal values and open
$('#modalTitle').html(event.title);
$('#modalBody').html(event.description);
$('#eventUrl').attr('href',event.url);
$('#fullCalModal').modal();
var my_variable = event.id; // here i take the event id

$.ajax({
url: 'ajax.php',
data: { var_PHP_data : my_variable },
type: "GET"
// here i send my id to my ajax page
});

Then in my ajax.php page I would simply do : 然后在我的ajax.php页面中,我会简单地做:

$event_id = $_GET['var_PHP_data'];

And in my main page where the modal popup is displayed i would simply do : 在显示模态弹出窗口的主页上,我会简单地执行以下操作:

<?php 

include("ajax.php");

echo $event_id;

?>

But that doesnt work because it's within the same page, and ajax is for remote pages. 但这不起作用,因为它在同一页面内,而ajax用于远程页面。

So is there a way to retrieve in that popup modal the event id ? 那么有没有办法在该弹出模式中检索事件ID?

for example I would like to do something like this in my modal 例如我想在我的模态中做这样的事情

<div id="fullCalModal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span> <span class="sr-only">close</span></button>
                <h4 id="modalTitle" class="modal-title"></h4>
            </div>
            <div id="modalBody" class="modal-body">
            <?php
$event_id = $_GET['event_id'];

//the use this event for mysql operations...

            ?>

You have a couple of options (though I'm a little confused because you can already set the event id in the modal window with something like $('#modalBody').html(event.id); ) 您有几种选择(尽管我有些困惑,因为您已经可以在模态窗口中使用$('#modalBody').html(event.id);类的东西来设置事件ID $('#modalBody').html(event.id);

1) I think the most efficient would be to just send back all the necessary event data in your event source. 1)我认为最有效的方法是将事件源中所有必要的事件数据发送回去。 You are already passing extra data like the description . 您已经传递了额外的数据,例如description You can add any extra fields you want to your source and then just pass it directly into the modal with event.SomeDataField . 您可以将任何想要的额外字段添加到源中,然后使用event.SomeDataField将其直接传递到模式中。 Customize that modal popup however you wish and add whatever extra fields you want. 根据需要自定义该模式弹出窗口,然后添加所需的任何其他字段。 This would be the ideal way because there is no need for AJAX for extra database calls. 这将是理想的方法,因为不需要额外的数据库调用就可以使用AJAX。

2) If there is too much data to pass and your events source would be too big if it were included, or you can't efficiently build that extra data into your source due to your database schema, then AJAX could work to retrieve the extra data. 2)如果要传递的数据太多,并且如果包含了事件源,那么事件源将太大,或者由于数据库架构的原因,您无法有效地将多余的数据构建到源中,那么AJAX可以检索多余的数据数据。 Just move all of the modal code inside the AJAX call so you set the values of the modal with the data you retrieved from the AJAX call. 只需将所有模态代码移动到AJAX调用中,即可使用从AJAX调用中检索到的数据设置模态值。 Something like: 就像是:

element.click(function() {    
    $.ajax({
        url: 'ajax.php',
        data: { var_PHP_data : event.id },
        type: "GET"
    }).done(function(data) {
        $('#modalTitle').html(event.title);
        $('#modalBody').html(data.extraDetails); //or whatever fields you are returning
        $('#eventUrl').attr('href',event.url);
        $('#fullCalModal').modal();
    });

3) If your modal window layout is getting too complex to easily manage, then consider templating the layout and return the needed HTML either from an AJAX call, or just make the content of the modal an iFrame and set the iFrame source on the element click event. 3)如果模态窗口布局过于复杂而无法轻松管理,则考虑对布局进行模板化,并通过AJAX调用返回所需的HTML,或者仅将模态的内容设置为iFrame, click在元素上设置iFrame源。事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM