是否有一种方法,我可以配置多个按钮在麻省理工学院的应用发明者屏幕做张贴不同的数据到谷歌表。据我所知,在谷歌脚本中只能有一个doPost()方法。
所以如果我在应用程序上有不同的按钮,我希望在谷歌应用程序脚本中调用不同的函数,我不知道该使用什么。我可以在MIT app inventor中为不同的按钮使用什么不同的标识符
感谢您可以使用parameters
来实现这一点,通过将按钮设置为指向不同的url,然后通过在doGet(e)中使用e.parameters
来检索用户的选择。
在你的HTML模板中,你可以构建链接/按钮来使用你想要的任何参数来调用你的应用程序,例如:
<!--The url comes from the template - see below-->
<a href="<?=url?>?functionOne=true">Function one</a>
<a href="<?=url?>?functionTwo=true">Function two</a>
脚本
function doGet(e){
var functionOne = e.parameter.functionOne;
var functionTwo = e.parameter.functionTwo;
//When functionOne is alled
if (functionOne =="true"){
//Do what you want here for function one
}
else if (functionTwo == "true"){
//Do what you want here for function two
}
else {
//This can be your base case here
}
模板中的URL
你需要在计算模板
之前包含脚本urltemplate.url = ScriptApp.getService().getUrl()