Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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
Javascript 弹出警报looops,如何停止循环?_Javascript_Google Apps Script - Fatal编程技术网

Javascript 弹出警报looops,如何停止循环?

Javascript 弹出警报looops,如何停止循环?,javascript,google-apps-script,Javascript,Google Apps Script,我试图有一个按钮,触发一个警报弹出窗口的信息从一个变量。它做它应该做的,但它不断循环。我做错了什么:) 以下是我在客户端的内容: <button class="green" id="insert-text" onclick="ReadData()">Markera</button> <script> function ReadData(data) { alert(data); google.script.run.withSu

我试图有一个按钮,触发一个警报弹出窗口的信息从一个变量。它做它应该做的,但它不断循环。我做错了什么:)

以下是我在客户端的内容:

 <button class="green" id="insert-text" onclick="ReadData()">Markera</button>

<script>
  function ReadData(data)
{
        alert(data);
      google.script.run.withSuccessHandler(ReadData)
      .GetDataFromSpreadsheet();
}
</script>

向同一个函数传递一个“withSuccessHandler”(创建一个无限循环:)。 您需要定义一个匿名函数:

function ReadData(data){
//   alert(data);   // not here :)
   google.script.run.withSuccessHandler(function(data){
      alert( data );
   }).GetDataFromSpreadsheet();
}
function handleData( data ){
   alert( data );
}

// [...]
google.script.run.withSuccessHandler( handleData ).GetDataFromSpreadsheet();
// [...]
或声明一个正常函数:

function ReadData(data){
//   alert(data);   // not here :)
   google.script.run.withSuccessHandler(function(data){
      alert( data );
   }).GetDataFromSpreadsheet();
}
function handleData( data ){
   alert( data );
}

// [...]
google.script.run.withSuccessHandler( handleData ).GetDataFromSpreadsheet();
// [...]
问候,, 凯文