如何将服务器端数据存储到Google Apps脚本中的客户端变量?

时间:2015-03-06 12:29:06

标签: javascript google-apps-script

我的服务器端功能检索一些电子表格数据。我想将这些数据存储在脚本标记内的客户端变量中:

<script>
function myFunction(){
    var data = new Array();
    data =google.script.run.getData(); // getData() is server side function.
}

当我为data使用console.log时,它没有显示任何内容。 我是否以正确的方式致电google.script.run

提前致谢。

1 个答案:

答案 0 :(得分:0)

当服务器端功能成功运行时,您必须编写一个回调函数来检索数据。

function myFunction() { 
    google.script.run.withSuccessHandler(onSuccess).getData();
}

function onSuccess(data) {
    //the argument data contains the array
}

有关更多信息和示例,请参阅此文档。

https://developers.google.com/apps-script/guides/html/reference/run

相关问题