首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何创建基本的FullCalendar自定义视图

问如何创建基本的FullCalendar自定义视图
EN

Stack Overflow用户
提问于 2017-04-11 15:33:24
回答 1查看 8K关注 0票数 12

下面的代码来自FullCalendar的Custom View文档。这似乎是一个很好的开始,但对于像我这样全新的人来说,拥有一些基本的代码来呈现最简单的自定义视图(带有一些事件)将是非常有帮助的。他们告诉您将BasicView和AgendaView作为参考,但这有点超出了我的理解。是否每个函数都需要在自定义类中被覆盖?

这个柱塞有一个基本的FullCalendar和一个可以切换到自定义视图的按钮。看一个有效的例子会很有帮助。我已经修修补补了几个小时,但没有成功的自定义视图。如果您了解FullCalendar并愿意为这些函数填写一些代码,将不胜感激!

https://plnkr.co/edit/gfEUCVYTWTm1md24e33m?p=preview

我的目标是构建一个日期列表,在可滚动的div中按顺序列出当天的所有事件(其中每个条目最终都将使用数据和css样式进行充实--我不确定listDay是否允许这种类型的定制??)。

代码语言:javascript
复制
var FC = $.fullCalendar; // a reference to FullCalendar's root namespace
var View = FC.View;      // the class that all views must inherit from
var CustomView;          // our subclass

CustomView = View.extend({ // make a subclass of View

    initialize: function() {
        // called once when the view is instantiated, when the user switches to the view.
        // initialize member variables or do other setup tasks.
    },

    render: function() {
        // responsible for displaying the skeleton of the view within the already-defined
        // this.el, a jQuery element.
    },

    setHeight: function(height, isAuto) {
        // responsible for adjusting the pixel-height of the view. if isAuto is true, the
        // view may be its natural height, and `height` becomes merely a suggestion.
    },

    renderEvents: function(events) {
        // reponsible for rendering the given Event Objects
    },

    destroyEvents: function() {
        // responsible for undoing everything in renderEvents
    },

    renderSelection: function(range) {
        // accepts a {start,end} object made of Moments, and must render the selection
    },

    destroySelection: function() {
        // responsible for undoing everything in renderSelection
    }

});
EN

回答 1

Stack Overflow用户

发布于 2017-09-09 19:19:44

我已经在您的柱塞中添加了几行代码,以使自定义视图正常工作。您可以在此处找到示例:https://plnkr.co/edit/8iOq15CsL2x6RPt29wgE?p=preview

仅提一下更改:在日历初始化器中添加了视图定义

代码语言:javascript
复制
$('#calendar').fullCalendar({
...
    views: {
            CustomView: {
                type: 'custom',
                buttonText: 'my Custom View',
                click:  $('#calendar').fullCalendar('changeView', 'CustomView')
            }
        }
});

在自定义视图中,刚刚在渲染中添加了这个

代码语言:javascript
复制
 $('.fc-view').append("<div>Insert your content here</div").css("background", "red");

在自定义视图中,您可以通过执行以下操作来访问事件:

代码语言:javascript
复制
var myEvents=$('#calendar').fullCalendar('clientEvents');

从那时起,您可以进行进一步的自定义

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43339490

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档