pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

Google Apps 腳本日歷服務(wù):僅獲取所有重復(fù)(全天)事

Google Apps Script Calendar Service: Get only the first events of all recurring (all day) events(Google Apps 腳本日歷服務(wù):僅獲取所有重復(fù)(全天)事件的第一個(gè)事件)
本文介紹了Google Apps 腳本日歷服務(wù):僅獲取所有重復(fù)(全天)事件的第一個(gè)事件的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

除了 這個(gè)問題 我想問一下如何有效地只檢索所有重復(fù)(全天)事件的第一個(gè)事件.為每個(gè)事件調(diào)用函數(shù) findFirstEvent() 似乎不合理.所以我的方法是過濾所有事件的數(shù)組.

In addition to this question I'd like to ask how to efficiently retrieve only the first events of all recurring (all day) events. To call the function findFirstEvent() for each single event seems not to be reasonable. So my approach would be to filter the array of all events.

var cal=CalendarApp.getCalendarById("Calendar Id");
var startTime=new Date(1850,0,1);
var endTime=new Date();
var events=cal.getEvents(startTime, endTime);
var firstEvents=events.filter(onlyFirstEvents);

function onlyFirstEvents() {
    ...
}

我最終真正需要的是一個(gè)數(shù)組,其中事件標(biāo)題為鍵,Date 對(duì)象為值.

What I actually need in the end is an array with the event titles as keys and Date objects as values.

推薦答案

  • 您想從 Google 日歷中檢索所有定期活動(dòng)和全天活動(dòng).
  • 特別是,您要檢索重復(fù)事件的開始事件的日期對(duì)象.
  • 您希望使用 Google Apps 腳本實(shí)現(xiàn)此目的.
  • 如果我的理解是正確的,那么這個(gè)答案呢?請(qǐng)認(rèn)為這只是幾個(gè)可能的答案之一.

    If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.

    • 本例使用isRecurringEvent()isAllDayEvent()方法.
    • getEvents() 按降序返回事件.使用它,可以檢索到您期望的結(jié)果.
    • In this case, the methods of isRecurringEvent() and isAllDayEvent() are used.
    • getEvents() returns the events with the descending order. Using this, the result you expect is retrieved.

    當(dāng)以上幾點(diǎn)反映到你的腳本中時(shí),它變成如下.

    When above points are reflected to your script, it becomes as follows.

    var firstEvents=events.filter(onlyFirstEvents);
    

    到:

    var firstEvents = events.reduce(function(ar, e) {
      var id = e.getId();
      if (e.isRecurringEvent() && e.isAllDayEvent() && !ar.some(function(f) {return f.eventId == id})) {
        ar.push({eventTitle: e.getTitle(), eventId: id, startDate: e.getAllDayStartDate(), endDate: e.getAllDayEndDate()});
      }
      return ar;
    }, []);
    

    結(jié)果:

    運(yùn)行上述腳本時(shí),返回以下值.

    Result:

    When above script is run, the following value is returned.

    [
      {
        "eventTitle": "###",
        "eventId": "###",
        "startDate": ### date object ###,
        "endDate": ### date object ###
      },
    ,
    ,
    
    ]
    

    參考資料:

    • isRecurringEvent()
    • isAllDayEvent()李>
    • getId()
    • 如果我誤解了您的問題并且這不是您想要的方向,我深表歉意.

      If I misunderstood your question and this was not the direction you want, I apologize.

      • 所以你會(huì) for 循環(huán)遍歷結(jié)果數(shù)組 firstEvents 以獲取所需的數(shù)組,其中事件標(biāo)題作為鍵,日期對(duì)象作為值?

      由此,我無法理解您想要一個(gè)數(shù)組還是一個(gè)對(duì)象.所以我想提出2種模式.在這種情況下,我認(rèn)為可以使用當(dāng)前腳本的firstEvents.

      From this, I cannot understand whether you want an array or an object. So I would like to propose 2 patterns. In this case, I thought that firstEvents of the current script can be used.

      在此模式中,返回一個(gè)數(shù)組,其中包括事件標(biāo)題和開始日期對(duì)象分別是鍵和值.請(qǐng)進(jìn)行如下修改.

      In this pattern, an array, which includes that the event titles and the start date object are the key and value, respectively, is returned. Please modify as follows.

      var firstEvents = events.reduce(function(ar, e) {
        var id = e.getId();
        if (e.isRecurringEvent() && e.isAllDayEvent() && !ar.some(function(f) {return f.eventId == id})) {
          ar.push({eventTitle: e.getTitle(), eventId: id, startDate: e.getAllDayStartDate(), endDate: e.getAllDayEndDate()});
        }
        return ar;
      }, []);
      firstEvents = firstEvents.map(function(e) {
        var obj = {};
        obj[e.eventTitle] = e.startDate;
        return obj;
      });
      

      模式2:

      在此模式中,返回一個(gè)對(duì)象,其中包括事件標(biāo)題和開始日期對(duì)象分別是鍵和值.

      Pattern 2:

      In this pattern, an object, which includes that the event titles and the start date object are the key and value, respectively, is returned.

      var firstEvents = events.reduce(function(ar, e) {
        var id = e.getId();
        if (e.isRecurringEvent() && e.isAllDayEvent() && !ar.some(function(f) {return f.eventId == id})) {
          ar.push({eventTitle: e.getTitle(), eventId: id, startDate: e.getAllDayStartDate(), endDate: e.getAllDayEndDate()});
        }
        return ar;
      }, []);
      firstEvents = firstEvents.reduce(function(obj, e) {
        obj[e.eventTitle] = e.eventTitle in obj ? obj[e.eventTitle].concat(e.startDate) : [e.startDate];
        return obj;
      }, {});
      

      這篇關(guān)于Google Apps 腳本日歷服務(wù):僅獲取所有重復(fù)(全天)事件的第一個(gè)事件的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

      【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創(chuàng)建頭像的 jQuery/JavaScript 庫(kù)?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設(shè)置值/標(biāo)簽的問題)
how to unit-test private methods in jquery plugins?(如何對(duì) jquery 插件中的私有方法進(jìn)行單元測(cè)試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動(dòng)網(wǎng)站配置偏移量/對(duì)齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當(dāng)文本框獲得焦點(diǎn)時(shí)選擇所有內(nèi)容)
主站蜘蛛池模板: 天津云仓-天津仓储物流-天津云仓一件代发-顺东云仓 | 山东PE给水管厂家,山东双壁波纹管,山东钢带增强波纹管,山东PE穿线管,山东PE农田灌溉管,山东MPP电力保护套管-山东德诺塑业有限公司 | 世纪豪门官网 世纪豪门集成吊顶加盟电话 世纪豪门售后电话 | 广州迈驰新GMP兽药包装机首页_药品包装机_中药散剂包装机 | 广东恩亿梯电源有限公司【官网】_UPS不间断电源|EPS应急电源|模块化机房|电动汽车充电桩_UPS电源厂家(恩亿梯UPS电源,UPS不间断电源,不间断电源UPS) | 上海网站建设-上海网站制作-上海网站设计-上海做网站公司-咏熠软件 | 帽子厂家_帽子工厂_帽子定做_义乌帽厂_帽厂_制帽厂_帽子厂_浙江高普制帽厂 | 应急灯_消防应急灯_应急照明灯_应急灯厂家-大成智慧官网 | 安徽合肥项目申报咨询公司_安徽合肥高新企业项目申报_安徽省科技项目申报代理 | 湖南自考_湖南自学考试网 | elisa试剂盒-PCR试剂盒「上海谷研实业有限公司」 | 碳钢法兰厂家,非标法兰,定制异型,法兰生产厂家-河北九瑞管道 | CTP磁天平|小电容测量仪|阴阳极极化_双液系沸点测定仪|dsj电渗实验装置-南京桑力电子设备厂 | 流变仪-热分析联用仪-热膨胀仪厂家-耐驰科学仪器商贸 | 中央空调维修、中央空调保养、螺杆压缩机维修-苏州东菱空调 | 震动筛选机|震动分筛机|筛粉机|振筛机|振荡筛-振动筛分设备专业生产厂家高服机械 | 直读光谱仪,光谱分析仪,手持式光谱仪,碳硫分析仪,创想仪器官网 | 金环宇|金环宇电线|金环宇电缆|金环宇电线电缆|深圳市金环宇电线电缆有限公司|金环宇电缆集团 | 深圳市源和塑胶电子有限公司-首页 | 专业深孔加工_东莞深孔钻加工_东莞深孔钻_东莞深孔加工_模具深孔钻加工厂-东莞市超耀实业有限公司 | 佛山商标注册_商标注册代理|专利注册申请_商标注册公司_鸿邦知识产权 | 金属软管_不锈钢金属软管_巩义市润达管道设备制造有限公司 | 吊篮式|移动式冷热冲击试验箱-二槽冷热冲击试验箱-广东科宝 | sus630/303cu不锈钢棒,440C/430F/17-4ph不锈钢研磨棒-江苏德镍金属科技有限公司 | 上海瑶恒实业有限公司|消防泵泵|离心泵|官网 | 耐磨陶瓷,耐磨陶瓷管道_厂家-淄博拓创陶瓷科技 | 东莞ERP软件_广州云ERP_中山ERP_台湾工厂erp系统-广东顺景软件科技有限公司 | 紫外线老化试验箱_uv紫外线老化试验箱价格|型号|厂家-正航仪器设备 | 智能型高压核相仪-自动开口闪点测试仪-QJ41A电雷管测试仪|上海妙定 | 模型公司_模型制作_沙盘模型报价-中国模型网 | 无锡装修装潢公司,口碑好的装饰装修公司-无锡索美装饰设计工程有限公司 | TPE_TPE热塑性弹性体_TPE原料价格_TPE材料厂家-惠州市中塑王塑胶制品公司- 中塑王塑胶制品有限公司 | 超声波清洗机_细胞破碎仪_实验室超声仪器_恒温水浴-广东洁盟深那仪器 | 江苏密集柜_电动_手动_移动_盛隆柜业江苏档案密集柜厂家 | 石油/泥浆/不锈钢防腐/砂泵/抽砂泵/砂砾泵/吸砂泵/压滤机泵 - 专业石油环保专用泵厂家 | 奥运星-汽车性能网评-提供个性化汽车资讯 | 食药成分检测_调料配方还原_洗涤剂化学成分分析_饲料_百检信息科技有限公司 | 冷柜风机-冰柜电机-罩极电机-外转子风机-EC直流电机厂家-杭州金久电器有限公司 | 防水套管|柔性防水套管|伸缩器|伸缩接头|传力接头-河南伟创管道 防水套管_柔性防水套管_刚性防水套管-巩义市润达管道设备制造有限公司 | 宁夏活性炭_防护活性炭_催化剂载体炭-宁夏恒辉活性炭有限公司 | 右手官网|右手工业设计|外观设计公司|工业设计公司|产品创新设计|医疗产品结构设计|EMC产品结构设计 |