Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
函数未从jquery google apps脚本调用_Jquery_Google Apps Script_Google Sheets - Fatal编程技术网

函数未从jquery google apps脚本调用

函数未从jquery google apps脚本调用,jquery,google-apps-script,google-sheets,Jquery,Google Apps Script,Google Sheets,因此,我有一个函数,当我运行时可以很好地工作,因为我可以看到它将数据输出到日志中,现在我想让它更加ui友好,并通过单击按钮调用该函数。我无法从ui中运行函数我缺少什么?请帮忙。这是我的密码 function showDialog() { var ui = HtmlService.createTemplateFromFile('Show') .evaluate().setWidth(300).setHeight(400);

因此,我有一个函数,当我运行时可以很好地工作,因为我可以看到它将数据输出到日志中,现在我想让它更加ui友好,并通过单击按钮调用该函数。我无法从ui中运行函数我缺少什么?请帮忙。这是我的密码

function showDialog()
          {
            var ui = HtmlService.createTemplateFromFile('Show')
            .evaluate().setWidth(300).setHeight(400);
            SpreadsheetApp.getUi().showModalDialog(ui, "Select a folder");
          }
    function generateFolderTree() {
      Logger.log("generateFolderTree called");
      try {


        var parentFolder = DriveApp.getRootFolder();

        getChildFolders(parentFolder);

      } catch (e) {

        Logger.log(e.toString());

      }

    }


    function getChildFolders(parent) {

      var childFolders = parent.getFolders();

      while (childFolders.hasNext()) {

        var childFolder = childFolders.next();

        Logger.log("Folder Name: " + childFolder.getName());

        var fold = childFolder.getName();
       }
    }




 Show.html

    <!-- USe a templated HTML printing scriphlet to import common stylesheet. -->
        <?!= HtmlService.createHtmlOutputFromFile("Stylesheet").getContent(); ?>
        <!-- Use a templated HTML printing scriptlet to import JavaScript. -->

        <div>
        <div class = "block" id = "dialog-elements">
        <button class = "selectFolder" id = "selectFolder" >Select a Folder</button>
        </div>
        <!-- This block is going to be hidden until the user selects a folder -->
        <div class = "block" id = "hiddenAttrib">
        <p><label for = "SelectedFolder"> Selected Folder: </label></p>
        <p><label id = "foldername"> Folder Name: </label></p>
        <p><label id = "folderid"> Folder ID: </label></p>
        </div>
        <div class = "folderTable" id = "folderTable">
        <p><label class = "showStatus" id = "dialog-status">Status: </label></p>
        <table style = "width:100%" id = "source">
        <!--<tr>
           <td> <button>Awesome</button></td>
        </tr>-->


        </table>


        </div>

        </div>
        <!-- Use a templated HTML printing scriptlet to import JavaScript. -->
        <?!= HtmlService.createHtmlOutputFromFile('ShowJavaScript').getContent(); ?>
jquery

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script>
    $(function(){
    $("button").click(runMyFunction);
    });
    function runMyFunction(){

    //this.disabled = true;
    google.script.run
    .withSuccessHandler(generateFolderTree)
    .withFailureHandler(showError)
     $("#hiddenAttrib").hide();
        var counter = 4;
        var i = 0;
        for (i = 0; i<counter; i++){
          var row = $("<p><tr><td><button>This is a test</button></td></tr></p>");
          $("#source").append(row.html());
    }
    }

    function showError(error) {
        console.log(error);
        window.alert('An error has occurred, please try again.');
      }
    </script

>

在“jquery”脚本中,您没有调用函数

调用它的模式应该是:

google.script.run
.withSuccessHandler(successCallback)
.withFailureHandler(errorCallback)
.appsscriptFunction()
google.script.run
.withSuccessHandler(successCallback)
.withFailureHandler(showError)
.generateFolderTree()
因此,对于您的情况,应该是:

google.script.run
.withSuccessHandler(successCallback)
.withFailureHandler(errorCallback)
.appsscriptFunction()
google.script.run
.withSuccessHandler(successCallback)
.withFailureHandler(showError)
.generateFolderTree()
在withSuccessHandler和withFailureHandler中使用的函数是客户端中的函数,与使用函数淋浴ROR时所做的相同,但在调用成功时还需要一个函数


您可以从中看到这一点。

非常感谢您修复了它并使其正常工作。非常感谢我将generateFolderTreess函数中的gen值存储在一个数组中,现在我需要将数组值传递到jquey并作为按钮附加到表中。有没有关于如何执行此操作的指针?在generateFolderTreess函数中返回该数组,但必须将其字符串化并返回JSON.stringifyarray。在客户端回调函数中,返回值将出现在函数的参数中,例如callBackresult{}。。。然后,您必须再次将该字符串转换为数组。。。var newArray=JSON.parseresult.valuescan无法让它工作,您能给我举个例子吗