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();
// [...]
问候,,
凯文