[英]Why is google apps script changing my user property to some random code every time I save it?
我正在为谷歌表格创建一个编辑器插件,我目前很难理解为什么每次我尝试使用setProperty
将其保存到此代码时都会更改我的用户属性( MY_WEBHOOK
):
function(){var L=h(fb(arguments));if(b&32)Vd(function(){a.apply(g||this,L)});else return m(a.apply(g||this,L))}
这是我正在使用的代码:
code.gs
:
function saveSettings(url) {
PropertiesService.getUserProperties().setProperty('MY_WEBHOOK', url);
SpreadsheetApp.getUi().alert("Saved")
}
function getSettings() {
return PropertiesService.getUserProperties().getProperty('MY_WEBHOOK');
}
在我的 html 文件中:
<body onload="get()">
<form>
<label>What is the URL?</label>
<input id="webhook-url" type="url" autofocus required placeholder="Webhook Here">
<br><br>
<input type="button" value="Save" onclick="save()">
<script>
function save() {
var url = document.getElementById('webhook-url').value
google.script.run.saveSettings(url)
alert(url)
alert(google.script.run.getSettings)
google.script.host.close()
}
function get() {
var settings = google.script.run.getSettings
document.getElementById('webhook-url').value = settings;
}
</script>
</form>
</body>
我认为您的脚本中有 2 个修改点。
google.script.run.getSettings
,在这种情况下, getSettings
的 function 没有运行。 请添加()
像google.script.run.getSettings()
。 通过这个,function 运行。
alert(google.script.run.getSettings)
和var settings = google.script.run.getSettings
, google.script.run
不返回任何值。 所以在这种情况下,使用withSuccessHandler
。google.script.run
与异步进程一起运行。当以上几点反映到您的脚本时,它变成如下。
请按如下方式修改您的 Javascript。
function save() {
var url = document.getElementById('webhook-url').value
google.script.run.withSuccessHandler(() => {
google.script.run.withSuccessHandler(e => {
alert(e);
google.script.host.close();
}).getSettings();
}).saveSettings(url);
}
function get() {
google.script.run.withSuccessHandler(settings => {
document.getElementById('webhook-url').value = settings;
}).getSettings();
}
get()
从getSettings
中获取值,当输入值并单击按钮时,通过saveSettings()
输入值,通过getSettings()
和alert()
获取当前值alert()
运行,然后google.script.host.close()
运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.