如何在谷歌应用制作器中处于自动保存模式时实现保存记录的回调功能?



我有一个处于自动保存模式的模型。当用户单击下面的按钮时,将执行以下代码。 我希望状态更改并保存,然后它应该执行刷新功能,因为刷新功能取决于状态值。但是在保存新状态之前,使用以下代码刷新功能将执行。

widget.datasource.item.status='inside';
refreshPanelWithColor();

我真正想做的是具有回调功能,但我无法使用 saveChanges,因为它仅适用于手动保存模式。

widget.datasource.item.status='inside';
widget.datasource.saveChanges(function() {
refreshPanelWithColor();
});

如何在不切换到手动保存模式的情况下实现回调功能?

正如马库斯在他的评论中所解释的那样,此功能目前不可用。当然,您可以使用另一种解决方案,即使用服务器脚本并重新加载数据源项。为了实现这一点,您的客户端脚本应如下所示:

var recordKey = widget.datasource.item._key;
var status = "inside";
google.script.run.withSuccessHandler(function(){
widget.datasource.item._reload(function(){
refreshPanelWithColor();
});
}).withFailureHandler(function(err){
console.err(err.toString());
}).updateDesiredRecord(recordKey, status);

当然,您需要实现从客户端调用的服务器脚本。它应该看起来像这样:

function updateDesiredRecord(recordKey, status){
var record = app.models.MYMODEL.getRecord(recordKey);
record.status = status;
app.saveRecords([record]);
}

我不确定您的refreshPanelWithColor()函数的作用,但我希望您了解此解决方案的意图。

您只需要在保存事件后将函数绑定到数据源即可。

最新更新