GAS PropertiesService to Save and Return Sort Order

前端 未结 2 1370
栀梦
栀梦 2021-01-16 01:28

QUESTION

How can I use PropertiesService to store an array from index.html, send the array to code.gs, and re

相关标签:
2条回答
  • 2021-01-16 02:12

    It's also possible to just use the browser's localStorage client side.

    localStorage.setItem('id', positions); //Store positions in users browser
    localStorage.getItem('id'); //Retrieve the stored positions later
    

    Notes:

    • For this to work, the url(document.domain of the iframe="*.googleusercontent.com") from which your script is deployed must remain constant. During my brief testing, it was constant even when changing from /dev to /exec of the parent(script.google.com) and even during version update. But there's no official reference.

    • This solution is better than properties service, if you have multiple users, as each one will have their own data stored in their own browsers and there are no server calls during each change.

    0 讨论(0)
  • 2021-01-16 02:28

    Using google.script.run simple example:

    <script>
    function sendStringToServer() {
      var string=$('#text1').val();
      google.script.run
      .withSuccessHandler(function(s){
        alert(s);
      })
      .saveString(string);
    }
    </script>
    

    Google Script:

    function myFunction() {
      PropertiesService.getScriptProperties().setProperty('MyString', string);
      return "String was saved in Service";
    }
    
    • Client to Server Communication
    0 讨论(0)
提交回复
热议问题