[英]Google Apps Script WebApp Pass html to file
這是此文章的后續內容。
我現在正嘗試使用模板文件,以便可以插入一些CSS等。我將其發布為Web應用程序。 輸出應該是iframe中Google Drive目錄中文件的列表。
加載消息出現在iframe中,但沒有出現任何語法錯誤,但目錄中的文件列表沒有出現。
code.gs:
function doGet() {
return HtmlService.createHtmlOutputFromFile('page');
}
function FileList() {
// my folder ID
var dir = '[MY_FOLDER_ID]';
var folder = DriveApp.getFolderById(dir);
var contents = folder.getFiles();
var filelist = [];
var file, name, url, idName = [];
while (contents.hasNext()) {
file = contents.next();
name = file.getName();
idName = name.toUpperCase();
url = file.getUrl();
// add table row html to filelist array
filelist = filelist.concat('<tr><td><a id="' + idName + '" target="_blank" href="' + url + '">' + name + '</a></td></tr>');
}
// alpha sort filelist array
filelist.sort();
// turn filelist into a string
filelist = filelist.join("");
return filelist;
}
page.html中:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function onSuccess(foo) {
var table = document.getElementById('output');
table.innerHTML = foo;
}
google.script.run.withSuccessHandler(onSuccess).getFileList();
</script>
</head>
<body>
<table id="output">Loading Files...</table>
</body>
</html>
您的代碼中有語法/錯別字:
google.script.run.withSuccessHandler(onSuccess).getFileList();
它應該是
google.script.run.withSuccessHandler(onSuccess).FileList();
由於Google腳本中的函數名稱是FileList而不是getFileList()。
提示:在運行網絡應用程序時,您可以使用Google chrome中的檢查或開發者控制台查看錯誤。(不確定是否知道)。
希望有幫助,祝你好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.