Google apps script 在模板和服务器端脚本(gs)之间传递值
我拥有的-3个文件Google apps script 在模板和服务器端脚本(gs)之间传递值,google-apps-script,local-storage,google-apps,google-slides,Google Apps Script,Local Storage,Google Apps,Google Slides,我拥有的-3个文件 sidebar.html(步骤1) model_less_dialog.html(步骤2) 服务器端脚本(.gs) 我想做什么: 我想在服务器端脚本上发送sidebar.html和model_less_dialog.html的值 我现有的解决方案与 localStorage.setItem('selectedSidebarValues',selectedData) 在模板和服务器端之间传递信息。我想找到在模板和服务器端脚本之间传递值的最佳实践,而不是localStorage(
localStorage.setItem('selectedSidebarValues',selectedData)代码>
在模板和服务器端之间传递信息。我想找到在模板和服务器端脚本之间传递值的最佳实践,而不是localStorage()
。用户可以在将其发送到服务器端脚本(.gs)之前修改localStorage()
,这可能很危险
Step-1 sidebar.html:
$("#selectBtn").on("click",function() {
-------------------
--- piece of code ---
-------------------
var selectedData = 'all selected values';
//storing step 1 selected data in local storage.
localStorage.setItem('selectedSidebarValues', selectedData);
//call the server script method to open the model less dialog box
google.script.run
.withSuccessHandler(
function(result, element) {
element.disabled = false;
})
.withFailureHandler(
function(msg, element) {
console.log(msg);
element.disabled = false;
})
.withUserObject(this)
.openModelLessDialogBox();
});
$("#selectBtnModelLessDialogBox").on("click",function(){
//collecting step 1 selected data from local storage.
var selectStep1 = localStorage.getItem('selectedSidebarValues');
var selectStep2 = 'all selected values';
//call the server script method
google.script.run
.withSuccessHandler(
function(result, element) {
element.disabled = false;
})
.withFailureHandler(
function(msg, element) {
console.log(msg);
element.disabled = false;
})
.withUserObject(this)
.calculatePolicy(selectStep1, selectStep2);
});
function openModelLessDialogBox() {
var ui = SlidesApp.getUi();
var htmlOutput = HtmlService
.createHtmlOutputFromFile('model_less_dialog')
.setWidth(250)
.setHeight(300);
ui.showModelessDialog(htmlOutput, 'model less dialog');
}
function calculatePolicy(selectStep1, selectStep2) {
----- ----- ---
----- ----- ---
----- ----- ---
}
Step-2 model\u less\u dialog.html:
$("#selectBtn").on("click",function() {
-------------------
--- piece of code ---
-------------------
var selectedData = 'all selected values';
//storing step 1 selected data in local storage.
localStorage.setItem('selectedSidebarValues', selectedData);
//call the server script method to open the model less dialog box
google.script.run
.withSuccessHandler(
function(result, element) {
element.disabled = false;
})
.withFailureHandler(
function(msg, element) {
console.log(msg);
element.disabled = false;
})
.withUserObject(this)
.openModelLessDialogBox();
});
$("#selectBtnModelLessDialogBox").on("click",function(){
//collecting step 1 selected data from local storage.
var selectStep1 = localStorage.getItem('selectedSidebarValues');
var selectStep2 = 'all selected values';
//call the server script method
google.script.run
.withSuccessHandler(
function(result, element) {
element.disabled = false;
})
.withFailureHandler(
function(msg, element) {
console.log(msg);
element.disabled = false;
})
.withUserObject(this)
.calculatePolicy(selectStep1, selectStep2);
});
function openModelLessDialogBox() {
var ui = SlidesApp.getUi();
var htmlOutput = HtmlService
.createHtmlOutputFromFile('model_less_dialog')
.setWidth(250)
.setHeight(300);
ui.showModelessDialog(htmlOutput, 'model less dialog');
}
function calculatePolicy(selectStep1, selectStep2) {
----- ----- ---
----- ----- ---
----- ----- ---
}
服务器端脚本(.gs):
$("#selectBtn").on("click",function() {
-------------------
--- piece of code ---
-------------------
var selectedData = 'all selected values';
//storing step 1 selected data in local storage.
localStorage.setItem('selectedSidebarValues', selectedData);
//call the server script method to open the model less dialog box
google.script.run
.withSuccessHandler(
function(result, element) {
element.disabled = false;
})
.withFailureHandler(
function(msg, element) {
console.log(msg);
element.disabled = false;
})
.withUserObject(this)
.openModelLessDialogBox();
});
$("#selectBtnModelLessDialogBox").on("click",function(){
//collecting step 1 selected data from local storage.
var selectStep1 = localStorage.getItem('selectedSidebarValues');
var selectStep2 = 'all selected values';
//call the server script method
google.script.run
.withSuccessHandler(
function(result, element) {
element.disabled = false;
})
.withFailureHandler(
function(msg, element) {
console.log(msg);
element.disabled = false;
})
.withUserObject(this)
.calculatePolicy(selectStep1, selectStep2);
});
function openModelLessDialogBox() {
var ui = SlidesApp.getUi();
var htmlOutput = HtmlService
.createHtmlOutputFromFile('model_less_dialog')
.setWidth(250)
.setHeight(300);
ui.showModelessDialog(htmlOutput, 'model less dialog');
}
function calculatePolicy(selectStep1, selectStep2) {
----- ----- ---
----- ----- ---
----- ----- ---
}
这就是我向服务器传递值的方式
最简单的方法是将数据传入:
- 边栏使用参数调用modaldialog
selectedData
.openModelLessDialogBox(selectedData);
- “模式”对话框有一个模板:
var selectStep1 = <?= sidebarData?>
另一种方法是通过window.top
直接通信。请参见ShowopenModelLessDialogBox
:)不,我只使用了单个脚本(gs)来实现此功能,但我想我理解了您上面的建议,@OLEGVALTE您建议的问题是应用程序脚本的异步执行。如果有多人在幻灯片上工作,在第二次执行期间,1个用户的第一个保存的边栏数据属性可能会被另一个用户覆盖。@TheMaster-hm,这可以通过LockService
来缓解。另外,为什么不先保存到用户属性并避免冲突?@OLEGVALTE Lock会很慢。但是,是的,没有想到用户属性。它应该解决这个问题。