前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >golang-fullcalendar拖曳drop、resize的坑

golang-fullcalendar拖曳drop、resize的坑

作者头像
hotqin888
发布2018-09-11 14:49:30
1.5K0
发布2018-09-11 14:49:30
举报
文章被收录于专栏:hotqin888的专栏

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1334404

由于看的都是旧的中文案例,导致在做日历事件拖曳和resize过程中走了弯路。还是应该看官方的文档啊。

正确的写法:

代码语言:javascript
复制
eventDrop: function(event,delta,revertFunc) {
          // alert(event.id+event.title+delta.days());
          // var url = "/admin/calendar/dropcalendar";
          // $.post(url,{id:event.id,dalta:delta.days()},function(msg){
          //   });
          $.ajax({
                type:"post",
                url:"/admin/calendar/dropcalendar",
                data: {id:event.id,delta:delta.days()},
                success:function(data,status){
                  alert("修改“"+data+"”成功!(status:"+status+".)");
                },
                error:function(data,status){
                  alert(data);
                  revertFunc();
                }
            });
        },
        eventResize: function(event,delta,revertFunc) {
          // alert(delta.asHours());
          $.ajax({
                type:"post",
                url:"/admin/calendar/resizecalendar",
                data: {id:event.id,delta:delta.asHours()},
                success:function(data,status){
                  alert("修改“"+data+"”成功!(status:"+status+".)");
                },
                error:function(data,status){
                  alert(data);
                  revertFunc();
                }
            });     
          }

重点就是

代码语言:javascript
复制
function( event, delta, revertFunc, jsEvent, ui, view ) { }
event is an Event Object that hold the event's information (date, title, etc). Call hasTime on the event's start/end to see if it has been dropped in a timed or all-day area (more info).

delta is a Duration Object that represents the amount of time the event was moved by. Available in version 2.0.1 and later.

Duration

Duration objects are used throughout the API. They are a creation of the MomentJS third-party library and can be instantiated with the moment.duration constructor.

Visit the MomentJS Duration docs

Hours 1.6.0+

edit

代码语言:javascript
复制
moment.duration().hours();
moment.duration().asHours();

As with the other getters for durations, moment.duration().hours() gets the hours (0 - 23).

moment.duration().asHours() gets the length of the duration in hours.

Days 1.6.0+

edit

代码语言:javascript
复制
moment.duration().days();
moment.duration().asDays();

As with the other getters for durations, moment.duration().days() gets the days (0 - 29).

moment.duration().asDays() gets the length of the duration in days.

当fullcalendar用drop的时候,这个duration用delta.days(),当fullcalendar用resize的时候,这个duration用delta.asHours()

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017年01月08日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Duration
    • Hours 1.6.0+
      • Days 1.6.0+
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档