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)容)
主站蜘蛛池模板: SDG吸附剂,SDG酸气吸附剂,干式酸性气体吸收剂生产厂家,超过20年生产使用经验。 - 富莱尔环保设备公司(原名天津市武清县环保设备厂) | 自清洗过滤器,浅层砂过滤器,叠片过滤器厂家-新乡市宇清净化 | 衬塑设备,衬四氟设备,衬氟设备-淄博鲲鹏防腐设备有限公司 | 烟台条码打印机_烟台条码扫描器_烟台碳带_烟台数据采集终端_烟台斑马打印机-金鹏电子-金鹏电子 | 屏蔽服(500kv-超高压-特高压-电磁)-徐吉电气 | 办公室家具公司_办公家具品牌厂家_森拉堡办公家具【官网】 | 环保袋,无纺布袋,无纺布打孔袋,保温袋,环保袋定制,环保袋厂家,环雅包装-十七年环保袋定制厂家 | 北京模型公司-工业模型-地产模型-施工模型-北京渝峰时代沙盘模型制作公司 | 档案密集架,移动密集架,手摇式密集架,吉林档案密集架-厂家直销★价格公道★质量保证 | 高通量组织研磨仪-多样品组织研磨仪-全自动组织研磨仪-研磨者科技(广州)有限公司 | 全自动包装秤_全自动上袋机_全自动套袋机_高位码垛机_全自动包装码垛系统生产线-三维汉界机器(山东)股份有限公司 | 辐射仪|辐射检测仪|辐射巡测仪|个人剂量报警仪|表面污染检测仪|辐射报警仪|辐射防护网 | 合肥弱电工程_安徽安防工程_智能化工程公司-合肥雷润 | 爱佩恒温恒湿测试箱|高低温实验箱|高低温冲击试验箱|冷热冲击试验箱-您身边的模拟环境试验设备技术专家-合作热线:400-6727-800-广东爱佩试验设备有限公司 | 气体热式流量计-定量控制流量计(空气流量计厂家)-湖北南控仪表科技有限公司 | 热风机_工业热风机生产厂家上海冠顶公司提供专业热风机图片价格实惠 | 北京网络营销推广_百度SEO搜索引擎优化公司_网站排名优化_谷歌SEO - 北京卓立海创信息技术有限公司 | 无线讲解器-导游讲解器-自助讲解器-分区讲解系统 品牌生产厂家[鹰米讲解-合肥市徽马信息科技有限公司] | 电脑知识|软件|系统|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网 | 工装定制/做厂家/公司_工装订做/制价格/费用-北京圣达信工装 | 洛阳防爆合格证办理-洛阳防爆认证机构-洛阳申请国家防爆合格证-洛阳本安防爆认证代办-洛阳沪南抚防爆电气技术服务有限公司 | 高博医疗集团上海阿特蒙医院 | 焊缝跟踪系统_激光位移传感器_激光焊缝跟踪传感器-创想智控 | 联系我们-腾龙公司上分客服微信19116098882 | 仓储货架_南京货架_钢制托盘_仓储笼_隔离网_环球零件盒_诺力液压车_货架-南京一品仓储设备制造公司 | 电机修理_二手电机专家-河北豫通机电设备有限公司(原石家庄冀华高压电机维修中心) | 定坤静电科技静电消除器厂家-除静电设备 | 贵州科比特-防雷公司厂家提供贵州防雷工程,防雷检测,防雷接地,防雷设备价格,防雷产品报价服务-贵州防雷检测公司 | 购买舔盐、舔砖、矿物质盐压块机,鱼饵、鱼饲料压块机--请到杜甫机械 | 全自动包装机_灌装机生产厂家-迈驰包装设备有限公司 | 等离子空气净化器_医用空气消毒机_空气净化消毒机_中央家用新风系统厂家_利安达官网 | 模切之家-专注服务模切行业的B2B平台! | 压砖机_电动螺旋压力机_粉末成型压力机_郑州华隆机械tel_0371-60121717 | 武汉创亿电气设备有限公司_电力检测设备生产厂家 | 不锈钢管件(不锈钢弯头,不锈钢三通,不锈钢大小头),不锈钢法兰「厂家」-浙江志通管阀 | 喷漆房_废气处理设备-湖北天地鑫环保设备有限公司 | IWIS链条代理-ALPS耦合透镜-硅烷预处理剂-上海顶楚电子有限公司 lcd条形屏-液晶长条屏-户外广告屏-条形智能显示屏-深圳市条形智能电子有限公司 | 济南轻型钢结构/济南铁艺护栏/济南铁艺大门-济南燕翔铁艺制品有限公司 | arch电源_SINPRO_开关电源_模块电源_医疗电源-东佑源 | 动物麻醉机-数显脑立体定位仪-北京易则佳科技有限公司 | 鹤壁创新仪器公司-全自动量热仪,定硫仪,煤炭测硫仪,灰熔点测定仪,快速自动测氢仪,工业分析仪,煤质化验仪器 |