2017-03-02 7 views
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>

答えて

0

スクリプトランナーのwithSuccessHandlerがありません。

https://developers.google.com/apps-script/guides/html/reference/run#withSuccessHandler(Function)

例:でドキュメントをチェックアウト

<script> 
    google.script.run 
    .withSuccessHandler(handleResults)  
    .processForm(searchTerm); 

    function handleResults(returnVal){ 
     console.log(returnVal) 
    } 
    </script> 
+0

おかげでスペンサー、私はこれのいくつかを試してみましたが、まだ結果が表示するために取得することはできませんよ。 submitを押すと、次のように表示されます。 for(var i = 0; i OblongMedulla

+0

スクリプトは配列を返すことができます。 'names'を返すだけです。 –

+0

index.htmlページのハンドル結果関数内に名前を追加したときに名前が定義されていないと言います – OblongMedulla

関連する問題