【问题标题】:Fullcalendar not showing in a modalFullcalendar 未在模式中显示
【发布时间】:2017-09-30 02:07:47
【问题描述】:

我正在使用 FullCalendar jQuery 插件来显示日历。

发生的情况是它不适用于引导模式。
我尝试了一些从互联网上获得的东西,但仍然没有运气。

请有人帮帮我。

<a href="#" id="see-doc-cal" data-toggle="modal" data-target="#doc-cal" >See Doctor Calendar</a>
<div class="modal fade" id="doc-cal" 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">Doctor's Appointments</h4>
      </div>

      <div class="modal-body">
        <div class="doctor-detail-wrap">
          <div id="doctor-calendar"></div>
        </div>
      </div>
      <div class="modal-footer">
        <!-- <input type="submit" class="btn btn-warning" id="doc-update" value="Update"> -->
        <button type="button" class="btn btn-default" id="plist-close" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

Main.js

$("#doctor-calendar").fullCalendar({
  header:{
    left:'prev',
    center:'title',
    right:'next'
  },
  defaultView:'agendaDay'
});

$('#doc-cal').on('shown.bs.modal', function () {
  $("#doctor-calendar").fullCalendar('render');
});

也试过这个

$(document).on("click","#see-doc-cal",function(){

  $('#doctor-calendar').fullCalendar();
});

【问题讨论】:

  • 打开模态弹窗时是否没有显示完整的日历?

标签: jquery twitter-bootstrap fullcalendar


【解决方案1】:

我用一个非常简单的技巧解决了这个问题;

首先 - 我找到在模态中添加“隐藏”属性的类(在我的情况下,我使用语义 ui,“模态”类对此负责)。

<div class = 'ui <!--long modal--> full-calendar'> 
    <div id="calendar"></div>
</div>

然后,在 jquery 代码中我这样做:

$('#calendar').fullCalendar({

    dayClick: function() {



    },
    weekends: false,
    showNonCurrentDates: false,
    locale: 'pt-br',
    render: true

});

$(".ui.full-calendar").addClass('long modal');//你可以把你隐藏的modal类放在这里。

这样日历会先呈现然后隐藏,在单击模式时显示。

【讨论】:

    【解决方案2】:

    我只添加了$("#doc-cal").modal(open);。

    必须打开模态才能看到它,对吗?
    或者也许你的问题是关于图书馆的加载......

    无论如何,它在CodePen 中工作得很好

    【讨论】:

    • 不,有一个锚标签可以打开模态,,
    • 所以检查库加载...因为它在 Codepen 中工作。控制台出错?
    • 控制台中没有错误..我认为这是因为当页面加载时,模式是隐藏的,当我们点击锚标记时,dom 会发生变化,但是我们的日历没有选择它,某事像这样。
    • 我更新了 Codepen 以使用打开模式的按钮...仍然有效。 “隐藏”是什么意思?使用 CSS 吗?如果是这样...只需使用.show()。我再次更新了 Codepen。
    • 我试过用你的锚切换...也可以。
    【解决方案3】:

    我使用下面的代码来渲染 fullCalendar,因为它隐藏在模式弹出窗口中。

    $('#doc-cal').on('shown.bs.modal', function () {
       $("#doctor-calendar").fullCalendar('render');
    })
    

    当包含它的元素隐藏在页面中时,不显示完整日历。请参阅工作示例。

    $('#doc-cal').on('shown.bs.modal', function () {
       $("#doctor-calendar").fullCalendar('render');
    })
    
    $("#doctor-calendar").fullCalendar({
        header:{
          left:'prev',
          center:'title',
          right:'next'
        },
        defaultView:'agendaDay'
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.js"></script>
    
    <link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.min.css" rel="stylesheet"/>
    
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    
    <a href="#" id="see-doc-cal" data-toggle="modal" data-target="#doc-cal" >See Doctor Calendar</a>
    
    <div class="modal fade" id="doc-cal" 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">Doctor's Appointments</h4>
          </div>
    
          <div class="modal-body">
            <div class="doctor-detail-wrap">
              <div id="doctor-calendar"></div>
            </div>
          </div>
          <div class="modal-footer">
            <!-- <input type="submit" class="btn btn-warning" id="doc-update" value="Update"> -->
            <button type="button" class="btn btn-default" id="plist-close" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>

    【讨论】:

    • 为什么这在我的系统中不起作用??包含库的顺序会有所不同吗?我的意思是首先我包括我的 css 文件,而不是在关闭 body 标记之前我包括我所有的 js 脚本。
    • 这实际上是一个很好的做法。问题可能是别的。
    猜你喜欢
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多