google web app script - global variable on client side

前端 未结 1 614
闹比i
闹比i 2021-01-28 14:08

I have a WebApp which takes some values from a google sheet when it is opened. I want to store a global variable so that I do not have to make a call to the server all the time

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-28 14:46

    The easiest way is store it as a global variable:

    var TEST;//Declare global
    google.script.run.withSuccessHandler(yourCallBack2).getPNInfo(body);
      
      function yourCallBack2(pinfo) {
        console.log("callback called");
        TEST = pinfo[0];//set global
      }
        
      function updateQ(){   
        var ea = TEST;//get global
        console.log(ea);
      }
    

    Other ways to persist information would be to use

    • Cookies
    • Session/Local storage

    google.script.run is a async call. So, updateQ might run before yourCallBack2 and your global variable TEST may be undefined by then.

    0 讨论(0)
提交回复
热议问题