0
我非常接近,但還沒有。記錄器顯示搜索結果 - 但是我仍然無法將結果顯示在Web應用程序中。從記錄器獲取結果以返回到網絡應用程序
在Web應用程序上的搜索確實有效,結果顯示在記錄器中。
請指教。謝謝!
這裏被更新,
代碼:
function SearchFiles(searchTerm) {
var searchFor ="title contains '" + searchTerm + "'";
var owneris ="and '[email protected]' in Owners";
var names =[];
var fileIds=[];
Logger.log(searchFor + " " + owneris);
var files = DriveApp.searchFiles(searchFor + " " + owneris);
while (files.hasNext()) {
var file = files.next();
var fileId = file.getId();// To get FileId of the file
fileIds.push(fileId);
var name = file.getName();
names.push(name);
}
for (var i=0;i<names.length;i++){
//this is showing in the Logger
Logger.log(names[i]);
Logger.log("https://drive.google.com/uc?export=download&id=" + fileIds[i]);
}
}
function returnNames() {
var names = SearchFiles();
return '<b>returnNames has ran.!</b> <br>' + names ;
}
function doGet(e) {
var template = HtmlService.createTemplateFromFile('Index');
return template.evaluate()
.setTitle('Hello World')
// .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function processForm(searchTerm) {
var resultToReturn;
Logger.log('processForm was called! ' + searchTerm);
resultToReturn = SearchFiles(searchTerm);
Logger.log('resultToReturn: ' + resultToReturn)
// shows as undefined in the logger
return resultToReturn;
}
function helloWorld()
{
return "Hello World!";
}
INDEX:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function displayMessage() {
var searchTerm;
searchTerm = document.getElementById('idSrchTerm').value;
console.log('searchTerm: ' + searchTerm);
google.script.run.processForm(searchTerm);
google.script.run.withSuccessHandler(handleResults).returnNames();
}
function handleResults(returnVal){
console.log('Handle Results was called! ');
document.writeln(returnVal);
}
</script>
</head>
<body>
<input type="text" id="idSrchTerm" name="search">
<input type="button" value="submitButton" name="submitButton" onclick="displayMessage()"/>
</body>
</html>
謝謝斯賓塞,我嘗試了一些這一點,但我仍然不能夠得到的結果顯示。按下提交時,如何顯示以下內容? for(var i = 0; i
OblongMedulla
你的腳本可以返回一個數組。只需返回'名稱'。 –
它說,當我在index.html頁面 – OblongMedulla