Javascript 为什么每次我保存时,谷歌应用程序脚本都会将我的用户属性更改为一些随机代码?
我正在为google sheets创建一个编辑器加载项,目前我很困惑,为什么每次我尝试使用Javascript 为什么每次我保存时,谷歌应用程序脚本都会将我的用户属性更改为一些随机代码?,javascript,google-apps-script,Javascript,Google Apps Script,我正在为google sheets创建一个编辑器加载项,目前我很困惑,为什么每次我尝试使用setProperty将我的用户属性(my_WEBHOOK)保存到以下代码时都会更改它: function(){var L=h(fb(参数));if(b&32)Vd(function(){a.apply(g | | this,L)};else返回m(a.apply(g | | this,L))} 以下是我正在使用的代码: code.gs: 函数保存设置(url){ PropertiesService.ge
setProperty
将我的用户属性(my_WEBHOOK
)保存到以下代码时都会更改它:
function(){var L=h(fb(参数));if(b&32)Vd(function(){a.apply(g | | this,L)};else返回m(a.apply(g | | this,L))}
以下是我正在使用的代码:
code.gs
:
函数保存设置(url){
PropertiesService.getUserProperties().setProperty('MY_WEBHOOK',url);
SpreadsheetApp.getUi().alert(“已保存”)
}
函数getSettings(){
返回PropertiesService.getUserProperties().getProperty('MY_WEBHOOK');
}
在我的html文件中:
什么是URL?
函数save(){
var url=document.getElementById('webhook-url')。值
google.script.run.saveSettings(url)
警报(url)
警报(google.script.run.getSettings)
google.script.host.close()
}
函数get(){
var settings=google.script.run.getSettings
document.getElementById('webhook-url')。值=设置;
}
修改点:
我认为您的脚本中有两个修改点
google.script.run.getSettings
,在本例中,getSettings
的功能不运行。请添加()
如google.script.run.getSettings()
。这样,函数就运行了。
- 我想这就是你的问题所在
alert(google.script.run.getSettings)
和var settings=google.script.run.getSettings
,google.script.run
不返回任何值。因此,在本例中,使用了带有SuccessHandler的
google.script.run
与异步进程一起运行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();
}
修改脚本:
请按如下方式修改您的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()
google.script.host.close()
- 这是一个简单的修改。因此,请根据您的实际情况进行修改
google.script.run.getSettings
,在本例中,getSettings
的功能不运行。请添加()
如google.script.run.getSettings()
。这样,函数就运行了。
- 我想这就是你的问题所在
alert(google.script.run.getSettings)
和var settings=google.script.run.getSettings
,google.script.run
不返回任何值。因此,在本例中,使用了带有SuccessHandler的
google.script.run
与异步进程一起运行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();
}
修改脚本:
请按如下方式修改您的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()
google.script.host.close()
- 这是一个简单的修改。因此,请根据您的实际情况进行修改
with SuccessHandler
(属于saveSettings
)缺少函数声明(常规或箭头声明)@Martí感谢您的评论。你说得对。那是因为我的复制粘贴错误。在本例中,在当前脚本中,首先运行内部google.script.run
。起初,我想提出像google.script.run.withSuccessHandler(google.script.run.withSuccessHandler(e=>{alert(e);google.script.host.close();}).getSettings)这样的建议代码>。但从你的评论来看,我认为这也是低可读性。根据您的评论,我可以使用arrow函数修改脚本。感谢您的支持。回答很好,但我认为您的代码有一个错误:withSuccessHandler
(属于saveSettings
)的第一个缺少函数声明(常规声明或箭头声明)@Martí感谢您的评论。你说得对。那是因为我的复制粘贴错误。在本例中,在当前脚本中,首先运行内部google.script.run
。起初,我想提出像google.script.run.withSuccessHandler(google.script.run.withSuccessHandler(e=>{alert(e);google.script.host.close();}).getSettings)这样的建议代码>。但从你的评论来看,我认为这也是低可读性。根据您的评论,我可以使用arrow函数修改脚本。谢谢你的支持。