【问题标题】:why my code have to call the function 2 times to get the correct value?为什么我的代码必须调用该函数 2 次才能获得正确的值?
【发布时间】:2021-02-13 12:21:41
【问题描述】:

我在客户端调用具有以下代码的函数,将数组发布到服务器端。 但服务器端首先对返回值响应 0。我必须再次调用该函数,然后它会返回正确的值。想知道是否有人知道我的代码有什么问题?谢谢!

客户端:

var array = [];
array.push(1, 2, 3);

google.script.run.withSuccessHandler(returnedScore).calScore(array);
function returnedScore(value) {
score = value;
return score;
}

服务器端:

function calScore(array) {
var value = 0;
value = array[0] - 5*array[1]*array[2]*2;
return value; 
}

【问题讨论】:

  • 传给服务器端的值是多少?你能发布输入数据吗

标签: javascript google-apps-script spreadsheet


【解决方案1】:

这对我有用:

function launchMyStupidDialog() {
  let html='<div id="msg"></div>';
  html+='<script>var array = [];array.push(1, 2, 3);google.script.run.withSuccessHandler(returnedScore).calScore(array);function returnedScore(value) {document.getElementById("msg").innerHTML=value;console.log(value);}</script>';
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html),'test');
}

function calScore(array) {
var value = 0;
value = array[0] - 5*array[1]*array[2]*2;
return value; 
}

【讨论】:

    猜你喜欢
    • 2022-01-05
    • 2011-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多