有没有办法用JavaScript参数调用函数gas?

时间:2018-12-24 14:45:10

标签: google-apps-script

我正在Google网站上工作,我有2个文件:“ code.gs”包含2个参数的函数,“ affichage.html”包含我的HTML代码。 我想用HTML文件中的参数在“附属项”中调用该函数。你有什么想法吗?

 function getFileIdFromFolder(folder_name,photo_name){
            var folders = DriveApp.getFoldersByName(folder_name);
            while (folders.hasNext()) {
                var folder = folders.next();
                var files = folder.getFilesByName(file_name);
                while (files.hasNext()) {
                     var file = files.next();
                     return file.getId();
                }
            }
        }
    <html>
       <script>
         var folder_name="folder";
         var file_name = "file";
         <? getFileIdFromFolder(folder,file); ?> 
       </script>
    </html>

1 个答案:

答案 0 :(得分:0)

尝试一下:

<html>
  <script>
    var foldername="folder";
    var filename = "file";
    google.script.run
    .withSuccessHandler(function(id){
      document.getElementById('displaydiv').innerHTML='<p>'+ id + '</p>';
    })
    .getFileIdFromFolder(foldername,filename);  
  </script>
</html>