如何将doGet(e)参数传递给另一个函数? [英] How to pass a doGet(e) parameter to another function?
问题描述
我可以从发布的应用程序脚本的url中捕获变量,但我不确定如何将该变量传递给另一个函数。如果包含变量,下面的脚本将不会运行onRun函数。我的目标是传递2个变量,但一次只能有一个问题。
函数doGet(e){
var id = e.parameter.id;
var minutes = e.parameter.min;
var html ='< p>'
+'< button onClick = google.script.run.onRun('+ id +')>运行<按钮>'//点击时不工作
+'< button onClick = google.script.run.onRun()>无参数运行< / button>'
+'< button onClick = google.script.run.turnOn()>开启< /按钮>'
+'<按钮onClick = google.script.run.turnOff()>关闭< /按钮>'
+ '< / p为H.';
返回HtmlService.createHtmlOutput(html).setSandboxMode(HtmlService.SandboxMode.IFRAME);
function onRun(id){
Logger.log(id:+ id);
}
诀窍是使用公共缓存(谢谢桑迪好)。
pre $ 函数doGet(e){
var id = e.parameter.id;
var minutes = e.parameter.min;
var cache = CacheService.getPublicCache();
cache.put(id,id,30);
cache.put(minutes,minutes,30);
var html ='< p>'
+'< button onClick = google.script.run.onRun()>无参数运行< / button>'$ b $ < / button>'
+'< button onClick = google.script.run.turnOff()>关闭< / b>> onClick = google.script.run.turnOn()>按钮>'
+'< / p>';
返回HtmlService.createHtmlOutput(html).setSandboxMode(HtmlService.SandboxMode.IFRAME);
函数onRun(id){
var cache = CacheService.getPublicCache();
var id = cache.get('id'));
var minutes = cache.get('minutes'));
}
I am able to capture a variable from the url of a published app script, but I am not sure how I can pass that variable to another function. The below script will not run the onRun function if a variable is included. My goal is to pass 2 variables, but one problem at a time.
function doGet(e) {
var id = e.parameter.id;
var minutes = e.parameter.min;
var html = '<p>'
+'<button onClick=google.script.run.onRun('+id+')>Run</button>' // Does not work when clicked
+'<button onClick=google.script.run.onRun()>Run without parameter</button>'
+'<button onClick=google.script.run.turnOn()>On</button>'
+'<button onClick=google.script.run.turnOff()>Off</button>'
+'</p>';
return HtmlService.createHtmlOutput(html).setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function onRun(id){
Logger.log("id: "+id);
}
The trick is to use a public cache (Thank you Sandy Good).
function doGet(e) {
var id = e.parameter.id;
var minutes = e.parameter.min;
var cache = CacheService.getPublicCache();
cache.put("id", id, 30);
cache.put("minutes", minutes, 30);
var html = '<p>'
+'<button onClick=google.script.run.onRun()>Run without parameter</button>'
+'<button onClick=google.script.run.turnOn()>On</button>'
+'<button onClick=google.script.run.turnOff()>Off</button>'
+'</p>';
return HtmlService.createHtmlOutput(html).setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function onRun(id){
var cache = CacheService.getPublicCache();
var id = cache.get('id'));
var minutes = cache.get('minutes'));
}
这篇关于如何将doGet(e)参数传递给另一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!