[英]Printing Array Values on Apps Script
How do you print all values in an array onto the modal dialog?如何将数组中的所有值打印到模态对话框中? I have tried the code below but it only prints the last array value.
我试过下面的代码,但它只打印最后一个数组值。
for (var count = 0; count < 10; count++) {
var htmlOutput = HtmlService.createHtmlOutput(arr[count]);
var arrayOutput = SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Test');
}
SpreadsheetApp.getUi().showModalDialog(HtmlService.createHtmlOutput(arr.join(","),"Test")
or或者
SpreadsheetApp.getUi().showModalDialog(HtmlService.createHtmlOutput(JSON.stringify(arr),"Test")
showModalDialog()
method does not suspend the server-side script while the dialog is open.showModalDialog()
方法在对话框打开时不会挂起服务器端脚本。
The script should show all the elements one by one.该脚本应一一显示所有元素。 But a newer dialog might close the older one.
但是较新的对话框可能会关闭旧的对话框。 So, you probably only see the last one.
所以,你可能只看到最后一个。 If you want to show all the elements in one dialog, use
JSON.stringify()
:如果要在一个对话框中显示所有元素,请使用
JSON.stringify()
:
SpreadsheetApp.getUi().showModalDialog(
HtmlService.createHtmlOutput(
JSON.stringify(arr,null,2)
), 'Test'
);
Or if you want to see them one by one, use Utilities.sleep()
:或者,如果您想一一查看它们,请使用
Utilities.sleep()
:
for (var count = 0; count < 10; count++) {
var htmlOutput = HtmlService.createHtmlOutput(arr[count]);
var arrayOutput = SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Test');
Utilities.sleep(15*1000);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.