【问题标题】:Google script gmail addon update TextInput value,on change function谷歌脚本 gmail 插件更新 TextInput 值,更改功能
【发布时间】:2018-02-09 12:35:56
【问题描述】:

我已经使用谷歌脚本创建了简单的 gmail 插件,因为我在这里遇到了困难,

如何在 setOnChangeAction 方法上更新 textinput 值,我检查了文档,我找不到任何方法

下面的代码我试过了,

var client_action = CardService.newAction().setFunctionName('clientId_callBack');
CardService.newTextInput()
  .setFieldName("clientId")
  .setTitle("Please enter clinet id")
  .setOnChangeAction(client_action)

function clientId_callBack(e){
  Logger.log("%s",JSON.stringify(e))
  e.formInput.clientId = "updatedValue";
}

提前致谢

【问题讨论】:

  • 关注Class SelectionInput 中的示例。根据示例,您应该在其中放置一个在 ChangeAction 发生时触发的函数。 setOnChangeAction(CardService.newAction() .setFunctionName("handleCheckboxChange"));

标签: google-apps-script gmail-addons


【解决方案1】:

如何解决这个问题?我认为可能还有其他方法。因此,请将此视为几个答案之一。在此示例脚本中,当输入foo 的值时,使用 CardBuilder 重构文本输入。使用此脚本时,作为测试,请输入foo。这是一个非常简单的 sn-p,因此请根据您的环境进行修改。

示例脚本:

function buildAddOn() {
  var card = CardService.newCardBuilder();
  card.setHeader(CardService.newCardHeader().setTitle("Sample"));
  var section = CardService.newCardSection();
  var action = CardService.newAction().setFunctionName('changeValue');
  section.addWidget(CardService.newTextInput().setFieldName("value").setTitle("Input \"foo\" as a value.").setOnChangeAction(action))
  return card.addSection(section).build()
}

function changeValue(e) {
  if (e.formInput.value == "foo") {
    var card = CardService.newCardBuilder();
    card.setHeader(CardService.newCardHeader().setTitle("Changed"));
    var section = CardService.newCardSection();
    var action = CardService.newAction().setFunctionName('getValue1');
    section.addWidget(CardService.newTextInput().setFieldName("value").setTitle("Got \"foo\".").setOnChangeAction(action).setValue("bar"))
    return card.addSection(section).build()
  }
}

如果我误解了你的问题,我很抱歉。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-22
    相关资源
    最近更新 更多