Google App Maker:如何访问绑定到小部件的项目的属性?

Google App Maker: How to access properties of an item bound to widget?

在 App maker 中,我创建了一个包含多个项目的数据源,这些项目显示在 table 上。当用户单击某个项目时,会弹出一个窗口,其中显示用户单击的项目的属性绑定到小部件。一旦用户单击弹出窗口中的保存按钮,我想在服务器脚本中获取当前项目的 ID。我怎样才能做到这一点?

您将需要使用异步操作。 official documentation 解释了如何实现这一点。基本上,您需要做类似这样的事情:

假设在服务器脚本上您有以下内容:

function doSomething(id){
    //do something
    if(!id){
        throw Error("Id is missing");
    }        
    return "ID = " + id;
}

然后在 SAVE 按钮上,你需要在 onClick 事件处理程序上有这样的东西:

var id = app.datasources.**yourDataSource**.item.id;
google.script.run.withFailureHandler(function(error){
    console.log(error);
).withSuccessHandler(function(response){
    console.log(response);
}).doSomething(id);

希望对您有所帮助!