我需要解析从谷歌脚本到HTML的数组

时间:2014-06-28 18:46:36

标签: html google-apps-script

我有一个日期选择器,我想用它来选择一个事件,然后从电子表格中显示详细信息。

HTML:

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Datepicker - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>

  $(function() {
    $( "#datepicker" ).datepicker({
        onSelect: function(date) {

            var stuff= updDate(date);

        },
        selectWeek: true,
        inline: true,
        startDate: '01/01/2000',
        firstDay: 1,
    });
  });
  </script>

    <script>
      function updDate(date){

      google.script.run.updDate(date);

      }


</script>
</head>


<body>

<p>Date: <input type="text" id="datepicker" onchange="updDate()"></p>
 Hello, world!
<input type="button" value="Close"
  onclick="google.script.host.close()" /> 
</body>
</html>

Google Script:

function updDate(date){

  var searchString = date;
  var data = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
  var s2 = SpreadsheetApp.openById("*************");
 var row = new Array();





  var k;


  for (var i in data) {
    //Logger.log("length is:  "+data[i].length)
    //var p = data[i].length
    for (var j in data[i]) {
      //Logger.log("We are at i:  "+i) //Row
      //Logger.log("We are at j:  "+j) //Col
      if (i !=0){
        if(data[i][j] != ""){
          if(j == 4){
            //Logger.log("date from picker:  " + date);
            //Logger.log("date from Data:  " + data[i][j]);
            var ssDate = Utilities.formatDate(data[i][j], "GMT", "MM/dd/yyyy");
            //Logger.log("date post Convert:  " +ssDate);
            if(date == ssDate){


              k= i
              var p = data[i].length
              Logger.log("P is:  " +p);

            }
          }

        }
        }
      }
    }
  Logger.log("K is:  "+k)

  var q = 1
  while (q <= p){

    row[q] = data[k][q];


    q++
  }

  Logger.log("Row:  " +row);
  return row;
  }

最终我想将数据读入表中,但是当我成功地将数据读入HTML中的变量时,我一直在寻找障碍。

现在我收到此错误:

  

未捕获的ScriptError:脚本已完成,但返回的值不是支持的返回类型。

任何帮助将数组“row”(在google脚本中)成功返回到变量“stuff”(在HTML中)或任何有关如何更好地执行此任务的指针都将非常感激。

洛伦

编辑代码:

   function updDate(date){


      var stuff = google.script.run.withSuccessHandler(myReturnFunction).updDate(date);
      Console.log(stuff)

      }
      function myReturnFunction(){
         window.myReturnFunction = function(whatGotReturned) {console.log(whatGotReturned);};

         }

1 个答案:

答案 0 :(得分:0)

Sandy Good在上面的评论中说得对:

 function updDate(date){


      var junk = google.script.run.withSuccessHandler(myReturnFunction).updDate(date);


      }
      function myReturnFunction(whatGotReturned){

        console.log(whatGotReturned);

         }