Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.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
Google apps script 在模板和服务器端脚本(gs)之间传递值_Google Apps Script_Local Storage_Google Apps_Google Slides - Fatal编程技术网

Google apps script 在模板和服务器端脚本(gs)之间传递值

Google apps script 在模板和服务器端脚本(gs)之间传递值,google-apps-script,local-storage,google-apps,google-slides,Google Apps Script,Local Storage,Google Apps,Google Slides,我拥有的-3个文件 sidebar.html(步骤1) model_less_dialog.html(步骤2) 服务器端脚本(.gs) 我想做什么: 我想在服务器端脚本上发送sidebar.html和model_less_dialog.html的值 我现有的解决方案与 localStorage.setItem('selectedSidebarValues',selectedData) 在模板和服务器端之间传递信息。我想找到在模板和服务器端脚本之间传递值的最佳实践,而不是localStorage(

我拥有的-3个文件

  • sidebar.html(步骤1)
  • model_less_dialog.html(步骤2)
  • 服务器端脚本(.gs)
  • 我想做什么: 我想在服务器端脚本上发送sidebar.html和model_less_dialog.html的值

    我现有的解决方案与

    localStorage.setItem('selectedSidebarValues',selectedData)

    在模板和服务器端之间传递信息。我想找到在模板和服务器端脚本之间传递值的最佳实践,而不是
    localStorage()
    。用户可以在将其发送到服务器端脚本(.gs)之前修改
    localStorage()
    ,这可能很危险

    Step-1 sidebar.html:

    $("#selectBtn").on("click",function() {
    
        -------------------
        --- piece of code ---
        -------------------
        
        var selectedData = 'all selected values';
    
        //storing step 1 selected data in local storage.
        localStorage.setItem('selectedSidebarValues', selectedData);
        
        //call the server script method to open the model less dialog box
        google.script.run
              .withSuccessHandler(
                  function(result, element) {
                      element.disabled = false;
                  })
              .withFailureHandler(
                  function(msg, element) {
                      console.log(msg);
                      element.disabled = false;
                  })
              .withUserObject(this)
              .openModelLessDialogBox();
      
    });
    
    $("#selectBtnModelLessDialogBox").on("click",function(){
    
        //collecting step 1 selected data from local storage.
        var selectStep1 = localStorage.getItem('selectedSidebarValues');
        var selectStep2 = 'all selected values';
    
        //call the server script method
        google.script.run
            .withSuccessHandler(
                function(result, element) {
                    element.disabled = false;
                })
            .withFailureHandler(
                function(msg, element) {
                    console.log(msg);
                    element.disabled = false;
                })
            .withUserObject(this)
            .calculatePolicy(selectStep1, selectStep2);
      });
    
    function openModelLessDialogBox() {
       var ui = SlidesApp.getUi();
       var htmlOutput = HtmlService
                               .createHtmlOutputFromFile('model_less_dialog')
                               .setWidth(250)
                               .setHeight(300);
       ui.showModelessDialog(htmlOutput, 'model less dialog');
    }
     
    function calculatePolicy(selectStep1, selectStep2) {
      ----- ----- --- 
      ----- ----- --- 
      ----- ----- ---
    }
    
    Step-2 model\u less\u dialog.html:

    $("#selectBtn").on("click",function() {
    
        -------------------
        --- piece of code ---
        -------------------
        
        var selectedData = 'all selected values';
    
        //storing step 1 selected data in local storage.
        localStorage.setItem('selectedSidebarValues', selectedData);
        
        //call the server script method to open the model less dialog box
        google.script.run
              .withSuccessHandler(
                  function(result, element) {
                      element.disabled = false;
                  })
              .withFailureHandler(
                  function(msg, element) {
                      console.log(msg);
                      element.disabled = false;
                  })
              .withUserObject(this)
              .openModelLessDialogBox();
      
    });
    
    $("#selectBtnModelLessDialogBox").on("click",function(){
    
        //collecting step 1 selected data from local storage.
        var selectStep1 = localStorage.getItem('selectedSidebarValues');
        var selectStep2 = 'all selected values';
    
        //call the server script method
        google.script.run
            .withSuccessHandler(
                function(result, element) {
                    element.disabled = false;
                })
            .withFailureHandler(
                function(msg, element) {
                    console.log(msg);
                    element.disabled = false;
                })
            .withUserObject(this)
            .calculatePolicy(selectStep1, selectStep2);
      });
    
    function openModelLessDialogBox() {
       var ui = SlidesApp.getUi();
       var htmlOutput = HtmlService
                               .createHtmlOutputFromFile('model_less_dialog')
                               .setWidth(250)
                               .setHeight(300);
       ui.showModelessDialog(htmlOutput, 'model less dialog');
    }
     
    function calculatePolicy(selectStep1, selectStep2) {
      ----- ----- --- 
      ----- ----- --- 
      ----- ----- ---
    }
    
    服务器端脚本(.gs):

    $("#selectBtn").on("click",function() {
    
        -------------------
        --- piece of code ---
        -------------------
        
        var selectedData = 'all selected values';
    
        //storing step 1 selected data in local storage.
        localStorage.setItem('selectedSidebarValues', selectedData);
        
        //call the server script method to open the model less dialog box
        google.script.run
              .withSuccessHandler(
                  function(result, element) {
                      element.disabled = false;
                  })
              .withFailureHandler(
                  function(msg, element) {
                      console.log(msg);
                      element.disabled = false;
                  })
              .withUserObject(this)
              .openModelLessDialogBox();
      
    });
    
    $("#selectBtnModelLessDialogBox").on("click",function(){
    
        //collecting step 1 selected data from local storage.
        var selectStep1 = localStorage.getItem('selectedSidebarValues');
        var selectStep2 = 'all selected values';
    
        //call the server script method
        google.script.run
            .withSuccessHandler(
                function(result, element) {
                    element.disabled = false;
                })
            .withFailureHandler(
                function(msg, element) {
                    console.log(msg);
                    element.disabled = false;
                })
            .withUserObject(this)
            .calculatePolicy(selectStep1, selectStep2);
      });
    
    function openModelLessDialogBox() {
       var ui = SlidesApp.getUi();
       var htmlOutput = HtmlService
                               .createHtmlOutputFromFile('model_less_dialog')
                               .setWidth(250)
                               .setHeight(300);
       ui.showModelessDialog(htmlOutput, 'model less dialog');
    }
     
    function calculatePolicy(selectStep1, selectStep2) {
      ----- ----- --- 
      ----- ----- --- 
      ----- ----- ---
    }
    
    这就是我向服务器传递值的方式


    最简单的方法是将数据传入:

    • 边栏使用参数调用modaldialog
      selectedData

      .openModelLessDialogBox(selectedData);
      
    • “模式”对话框有一个模板:

      var selectStep1 = <?= sidebarData?>
      

    另一种方法是通过
    window.top
    直接通信。请参见

    Show
    openModelLessDialogBox
    :)不,我只使用了单个脚本(gs)来实现此功能,但我想我理解了您上面的建议,@OLEGVALTE您建议的问题是应用程序脚本的异步执行。如果有多人在幻灯片上工作,在第二次执行期间,1个用户的第一个保存的边栏数据属性可能会被另一个用户覆盖。@TheMaster-hm,这可以通过
    LockService
    来缓解。另外,为什么不先保存到用户属性并避免冲突?@OLEGVALTE Lock会很慢。但是,是的,没有想到用户属性。它应该解决这个问题。