您好我在Google表格上使用Google App Scripts,我想组织我的代码,所以我尝试封装了一些功能。但是,我似乎无法弄清楚如何从html模板调用封装函数。
是否有人知道是否可以使用html模板中的google.script.run调用封装函数?
示例:
Code.gs
function onOpen(e){
var menu = SpreadsheetApp.getUi().createMenu('Document Routing')
.addItem('View/Edit My Routes', 'ViewMyRoutes')
.addToUi();
}
function ViewMyRoutes() {
var html = HtmlService.createHtmlOutputFromFile('MyRoutes')
.setTitle('My Routes')
.setWidth(300);
SpreadsheetApp.getUi()
.showSidebar(html);
}

User.gs
var User = function(){
return {
GetMyRoutes: function (){
var userProperties = PropertiesService.getUserProperties();
var routeData = userProperties.getProperty("SpreadsheetRoutes");
return routeData;
}
};
}();

Sample.html
<h1>Edit Route</h1>
<select id="EditRoute" onchange="LoadSelectedRoute()"></select>
<div id='divRoutes'></div>
<script>
function LoadEditDropDown(){
google.script.run
.withFailureHandler(onFailure)
.withSuccessHandler(OnGetRoutesSuccess)
.User.GetMyRoutes();
function OnGetRoutesSuccess(scriptProperties){
//do stuff with scriptProperties here
}
}
LoadEditDropDown();
</script>
&#13;
答案 0 :(得分:0)
这个怎么样?在这种情况下,我使用这种方式。但我不知道这是否是最佳方式。对不起我担心这可能是你想要的相反方式。
function UserGetMyRoutes() {
return User.GetMyRoutes();
}
google.script.run
,如下所示google.script.run
.withFailureHandler(onFailure)
.withSuccessHandler(OnGetRoutesSuccess)
.User.GetMyRoutes();
google.script.run
.withFailureHandler(onFailure)
.withSuccessHandler(OnGetRoutesSuccess)
.UserGetMyRoutes();