Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.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
如何将两个数组的值获取到相同的html javascript_Javascript_Arrays_Google Apps Script - Fatal编程技术网

如何将两个数组的值获取到相同的html javascript

如何将两个数组的值获取到相同的html javascript,javascript,arrays,google-apps-script,Javascript,Arrays,Google Apps Script,我在谷歌应用程序脚本中有两个函数 代码G.gs: function getdata1(e) { // works.. return array_1; } function getdata2(e) { // works.. return array_2; } index.html: function getData1(e) { google.script.run.withSuccessHandler(dispData1).getData1(e); } function dispD

我在谷歌应用程序脚本中有两个函数

代码G.gs:

function getdata1(e) {
// works..
return array_1;
}

function getdata2(e) {
// works..
return array_2;
}

index.html:

function getData1(e) {
  google.script.run.withSuccessHandler(dispData1).getData1(e);    
}
function dispData1(array_1) {
// here i can acces the value of array_1.
// NOW i need to access the values of array_2 from the other function (getData2)
}

感谢您的帮助

添加一个名为getAllData()的中间函数

然后从html调用getAllData

//.html file
function getAllData(e) {
  google.script.run.withSuccessHandler(dispData).getAllData(e);    
}

function dispData(response) {
 var array_1 = response.array_1
 var array_2 = response.array_2
}

要同时运行这两个功能,请使用:

//.html file
function getAllData(e) {
  google.script.run.withSuccessHandler(dispData).getAllData(e);    
}

function dispData(response) {
 var array_1 = response.array_1
 var array_2 = response.array_2
}
const gsr = func =>
  new Promise(res => google.script.run.withSuccessHandler(res)[func]());

Promise.all(['getdata1', 'getdata2'].map(f => gsr(f))).then(
  ([arr1, arr2]) => {
    console.log({ arr1, arr2 });
  }
);