简体   繁体   English

在fullcalendar事件点击时填充bootstrap 3模态窗口

[英]populating a bootstrap 3 modal window on fullcalendar event click

Trying to leverage fullcalendar.io to populate a series of events. 尝试利用fullcalendar.io填充一系列事件。 I've got my events working and the callback function when an event is clicked functioning as well. 单击事件后,我的事件也将正常工作,回调函数也将起作用。

What I want to do is open a bootstrap modal that will populate it's content area with an ajax call to my php backend. 我想做的是打开一个引导程序模版,它将使用对我的php后端的ajax调用来填充其内容区域。 This will allow me to display the event details in that modal window. 这将允许我在该模式窗口中显示事件详细信息。

Below is my latest attempts at making this work: 以下是我进行这项工作的最新尝试:

        <!-- Modal -->
    <div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div id="modal-body" class="modal-body">

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

    </div>
    </div>

    <!-- This file should primarily consist of HTML with a little bit of PHP. -->
    <div id='calendar'>

    </div>    

    <script>
        jQuery(document).ready(function () {

            // set up the modal to be an ajax pull.
            jQuery("#myModal").on("show.bs.modal", function(e) {
                var link = jQuery(e.relatedTarget);
                jQuery(this).find(".modal-body").load(link.attr("href"));
            });

            // set up the calendar
            jQuery('#calendar').fullCalendar({
               header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            height: 650,
            editable: false,
            eventLimit: true, // allow "more" link when too many events
            eventSources: [
              {
                url :'<?php echo esc_url( admin_url('admin-post.php') ); ?>',
                color: 'yellow',
                textColor: 'black',
                type: 'POST',
                data: {
                    action: 'fun_events_feed'
                }
              }
            ],          
            // toggle the display of the modal window when an event is clicked.
            eventClick: function(calEvent, jsEvent, view) {                                                          
                jQuery.get( '/fun-intra/event-data.php', null, function(data){
                    jQuery('#modal-body').html(data);
                    jQuery('#myModal').modal('toggle');
                });                
            },
            });
        });
    </script>

when trying to open the modal window with an event click, the console spits out this error: 尝试通过事件单击打开模式窗口时,控制台会吐出此错误:

(index):183 Uncaught TypeError: jQuery(...).modal is not a function

I suspect I have a scoping issue, is there a way to pass in the jquery selected object so that I can toggle the display of the modal AFTER it has loaded within the .get callback? 我怀疑我有一个范围问题,是否有一种方法可以传入jquery选定的对象,以便在加载到.get回调中之后可以切换模态的显示? Once I have this working then I can easily add in the required parameters of the eventId so that my backend can fetch the correct event. 完成这项工作后,便可以轻松添加eventId的必需参数,以便后端可以获取正确的事件。

Managed to find the answer last night after much google searching. 经过大量Google搜索,昨晚设法找到了答案。

<script>
jQuery(document).ready(function () {

    // set up the calendar
    jQuery('#calendar').fullCalendar({
       header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    height: 650,
    editable: false,
    eventLimit: true, // allow "more" link when too many events
    eventSources: [
      {
        url :'<?php echo esc_url( admin_url('admin-post.php') ); ?>',
        color: 'yellow',
        textColor: 'black',
        type: 'POST',
        data: {
            action: 'fengate_events_feed'
        }
      }
    ],
    // toggle the display of the modal window when an event is clicked.
    eventClick: function(calEvent, jsEvent, view) {
        console.log(calEvent);
        jQuery("#modal-body").load('<?php echo esc_url( admin_url('admin-post.php') ); ?>?action=event_modal&id=' + calEvent.id);
        jQuery("#myModal").modal('toggle');
    },
    });
});

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

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