我想知道当我关闭对话框时是否有办法更新卡片
//this function is called when click a button in the card
function showDialog() {
const html = HtmlService.createHtmlOutputFromFile('dialog.html')
.setWidth(600)
.setHeight(425)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi().showModalDialog(html, 'Select the spreadsheets');
}
//this function is called by client code
function callback(text) {
var card = CardService.newCardBuilder().build();
var navigation = CardService.newNavigation().updateCard(card);
return CardService.newActionResponseBuilder()
.setNavigation(navigation)
.setNotification('Import Succeed')
.build();
}
dialog.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css">
<script>
function onApiLoad() {
gapi.load('picker', {'callback': function() {
......
}});
}
function createPicker(token) {
if (pickerApiLoaded && token) {
var picker = new google.picker.PickerBuilder()
.addView(new google.picker.DocsView(google.picker.ViewId.SPREADSHEETS)
.setMode(google.picker.DocsViewMode.LIST)
.setCallback(pickerCallback)
.........
.build();
picker.setVisible(true);
} else {
showError('Unable to load the file picker.');
}
}
function pickerCallback(data) {
var action = data[google.picker.Response.ACTION];
if (action == google.picker.Action.PICKED) {
google.script.run.callback('');
google.script.host.close();
} else if (action == google.picker.Action.CANCEL) {
google.script.host.close();
}
}
</script>
</head>
<body>
<script src="https://apis.google.com/js/api.js?onload=onApiLoad"></script>
</body>
</html>
我可以在当前电子表格开发人员元数据中写入文本,并在卡中检查开发人员元数据中的死循环,如下面的代码,但如果用户没有及时关闭对话框,google会在卡中抛出超时错误
//this function is called when click a button in the card
function showDialog() {
const html = HtmlService.createHtmlOutputFromFile('dialog.html')
.setWidth(600)
.setHeight(425)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi().showModalDialog(html, 'Select the spreadsheets');
//But I must return a response within a certain time since google has time limit for response
var metadataList = SpreadsheetApp.getActive().getDeveloperMetadata();
//find the text in the metadataList, and return the response
}
//this function is called by client code
function callback(text) {
//updat the card with text
SpreadsheetApp.getActive().addDeveloperMetadata('text', text);
}
Tl;Dr当对话框关闭时,无法更新卡片。
虽然编辑器附加组件和工作区附加组件可能共享相同的Google Apps Script项目/Google Cloud项目,但它们仍然是两个不同的附加组件。此时,没有办法直接通信两个附加组件。
工作区外接程序没有文件编辑/更改的触发器,只有用户点击卡片按钮时才有。
对于你目前的方法,我认为你唯一能做的就是向用户提供重新打开卡片的指令。
相关的
- 通过Workspace Add-On更改可见性设置后更新Google Calendar UI
- 如何完全刷新谷歌插件卡(谷歌表),其中包括一个下拉菜单填充使用表数据时,数据的变化?
- 是否可以从可安装的触发功能刷新谷歌工作空间附加组件侧边栏卡?