在 Appmaker 中动态加载下拉值

Load Dropdown values dynamically in Appmaker

我有一个用例,我需要在下拉列表中显示用户的团队驱动器名称,我已经编写了一个代码来为用户获取团队驱动器的名称,但我无法在下拉列表中动态加载这些值.

在下拉小部件 "options" 标记中,我正在进行函数调用,它调用服务器来获取这些数据并调用服务器 returns 值。但是没有反映相同的数据。

这是我的片段,

function fetchValues() {
  google.script.run
    .withFailureHandler(function(error) {
      app.closeDialog();  
      setNotificationText(error);
      app.popups.Snackbar.visible = true;
    })
    .withSuccessHandler(function(result) {
      // This result has the list of team drive names.
      return result;
    })
    .fetchValues();  
}

你的客户端脚本函数fetchValues returns undefined,你可以使用开发工具控制台测试它:

console.log(fetchValues());

这是由于客户端(浏览器)和服务器之间通信的异步性质而发生的(您可以了解更多信息 here and here)。修复当前代码的最简单直接的方法是更改​​对此的绑定:

fetchValues(@widget);

并将您的函数更改为此

function fetchValues(dropdown) {
  google.script.run
    .withFailureHandler(function(error) {
      ...
    })
    .withSuccessHandler(function(result) {
      dropdown.options = result;
    })
    .fetchValues();  
}

但总的来说,这似乎不是在 App Maker 中填充下拉菜单 optionsnames 的正确方法。我会考虑使用 Calculated Model or Custom Properties

重做这部分