如何使用Apps脚本重新启动

如何使用Apps脚本重新启动

本文介绍了如何使用Apps脚本重新启动/更新/刷新卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做噩梦时使用Apps Script进行了许多场景,但是没有任何效果!我有一个使GET请求返回纸牌数组的函数.现在,有时我需要这张卡再次刷新以获取新内容.

I'm having a nightmare doing a lot of scenarios using Apps Script, but nothing works! I have a function that makes a GET request returns an array of cards. Now, sometimes I need this card refreshes again to fetch the new content.

function listTemplatesCards(){
  var getAllTemplates = getTemplates();
  var allTemplates = getAllTemplates.templates;
  var theUserSlug = getAllTemplates.user_slug;
  var templateCards = [];

  //There are templates
  if(allTemplates.length > 0){
    allTemplates.forEach(function(template){
      templateCards.push(templateCard(template, theUserSlug).build());
    });
    return templateCards;
  }
}

onTriggerFunction上调用此函数.现在,如果我移到另一张卡,并且想以干净清晰的方式再次回到根,我会用到它,但是它不起作用:

This function is called on onTriggerFunction. Now, if I moved to another card and I wanted to back again to the root but in clean and clear way, I use this but it doesn't work:

  //Move the user to the root card again
  var refreshNav = CardService.newNavigation().popToRoot();
  return CardService.newActionResponseBuilder().setStateChanged(true).setNavigation(refreshNav).build();

简而言之,我想要的是,一旦用户单击Refresh按钮,卡就会刷新/更新自身,以再次进行呼叫并获取新数据.

Simply, what I want is once the user clicks on Refresh button, the card refreshes/updates itself to make the call again and get the new data.

推荐答案

我发现这样做的唯一方法是始终使用单个卡作为根.在主函数(在appscript.json onTriggerFunction中命名)中,仅返回一张卡,而不返回卡的数组.然后,您可以使用popToRoot().updateCard(...),它会起作用.

The only way I've found to do this is to always use a single card for the root. In the main function (named in the appscript.json onTriggerFunction), return only a single card, not an array of cards. You can then use popToRoot().updateCard(...) and it works.

这篇关于如何使用Apps脚本重新启动/更新/刷新卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 22:57