Javascript “谷歌应用程序脚本访问值来自”对话框
我按照本教程在GoogleSheets中创建了一个对话框并打印了值。但是,我想将这些值输入到一个新函数中。如果我试图在第29行中访问它们,代码会有些中断。我之所以说“有点”,是因为它一直运行到第28行,但我认为它不会执行第28行,因为我在日志中看不到任何内容 我还注意到,当我添加两行新行时,它不会自动关闭对话框。我假设它与testUI.html中的closeIt函数有关,但我不知道它是什么,因为我是jQuery/Javascript新手 代码.gsJavascript “谷歌应用程序脚本访问值来自”对话框,javascript,jquery,google-apps-script,Javascript,Jquery,Google Apps Script,我按照本教程在GoogleSheets中创建了一个对话框并打印了值。但是,我想将这些值输入到一个新函数中。如果我试图在第29行中访问它们,代码会有些中断。我之所以说“有点”,是因为它一直运行到第28行,但我认为它不会执行第28行,因为我在日志中看不到任何内容 我还注意到,当我添加两行新行时,它不会自动关闭对话框。我假设它与testUI.html中的closeIt函数有关,但我不知道它是什么,因为我是jQuery/Javascript新手 代码.gs //--GLOBALS-- var ui
//--GLOBALS--
var ui = SpreadsheetApp.getUi();
function onOpen(e) {
// Create menu options
ui.createAddonMenu()
.addSubMenu(ui.createMenu("Admin")
.addItem("Test", "test"))
.addToUi();
};
function test() {
//Call the HTML file and set the width and height
var html = HtmlService.createHtmlOutputFromFile("testUI")
.setWidth(450)
.setHeight(300);
//Display the dialog
var dialog = ui.showModalDialog(html, "Select the relevant module and unit");
};
function runsies(values) {
//Display the values submitted from the dialog box in the Logger.
Logger.log(values);
//I added the two lines below because I'd like to access the values, not just print them.
var valuesAcc = values[0]["orange"]
Logger.log(valuesAcc);
};
//I'd like to run another function after runsies so I can work with the values which were inputted
//into the dialogue box.
src=“//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js”>
函数形式_数据(){
var值=[{
“橙色”:$(“输入[名称=橙色]:选中”).val(),
“蓝色”:$(“输入[名称=蓝色]:选中”).val(),
“绿色”:$(“输入[名称=绿色]:选中”).val(),
“紫色”:$(“输入[名称=紫色]:选中”).val()
}];
google.script.run.withSuccessHandler(closeIt.runsies(值);
};
函数closeIt(){
google.script.host.close()
};代码>
单位:
模块
不适用
1
2
3
4
5
6
7
8
橙色
蓝色
绿色
紫色
使用google.script.run可以轻松地从对话框中访问值。有关信息,请访问
下面是我已经完成的几个对话框示例: