【问题标题】:How do I use setTimeout function in my JS script如何在我的 JS 脚本中使用 setTimeout 函数
【发布时间】:2022-09-23 00:04:39
【问题描述】:

我正在尝试在 Airtable 中创建一个链接到按钮的脚本。过程如下:

  1. Airtable 中的按钮被按下
  2. 如果复选框字段\'Jira switch\'为假,则将其变为真
  3. 等待 2 秒,将字段重置为 false

    这是我使用 setTimeout() 函数编写的脚本:

    let table = base.getTable(\"XOS\"); //The name of the table you\'re in here
    let record = await input.recordAsync(\'Pick a record\', table);
    if (record) {
       
     if (record.getCellValue(\"Jira switch\")===false) {
        table.updateRecordAsync(record, {\'Jira switch\': true});
        output.text(\'checkbox ticked\');
     } 
     
    const myTimeout = setTimeout(timeDelay, 2000);
       function timeDelay()
          table.updateRecordAsync(record, {\'Jira switch\': false});
          output.text(\'2 second interval\');
        
    }
    

    当我编写代码时,我收到一条错误消息\"找不到名称 setTimeout\".作为一种解决方案,它建议\"添加缺少的函数声明\'setTimeout\'\"

    如何声明此函数以便它可以与我的代码一起运行?

    标签: javascript airtable


    【解决方案1】:

    我认为你的语法有问题。 在function timeDelay() 之后,您忘记添加花括号来声明函数内部的代码。

    【讨论】:

      【解决方案2】:

      缺少大括号{

      let table = base.getTable("XOS"); //The name of the table you're in here
      let record = await input.recordAsync('Pick a record', table);
         
       if (record.getCellValue("Jira switch")===false) {
          table.updateRecordAsync(record, {'Jira switch': true});
          output.text('checkbox ticked');
       } 
       
      const myTimeout = setTimeout(timeDelay, 2000);
         function timeDelay() {/*========> missing curly bracket*/
            table.updateRecordAsync(record, {'Jira switch': false});
            output.text('2 second interval');
          
      }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-07
        • 2019-07-09
        • 1970-01-01
        • 2020-10-24
        • 2022-01-10
        • 1970-01-01
        • 2017-11-02
        • 2021-01-25
        相关资源
        最近更新 更多