在选择下拉列表时,检索数据为空,但在Google Web应用程序中选择的第一项除外 [英] On selection of dropdown retrieve data is null except the first item selection in google web app

查看:70
本文介绍了在选择下拉列表时,检索数据为空,但在Google Web应用程序中选择的第一项除外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google网络应用程序。我想根据下拉选择检索数据。我只能从下拉列表中选择第一个项目,就可以完美地检索数据,其余的我将收到空数组。我已经通过手动调用检查了服务器端代码,它的工作正常,并且可以完美地发送数据。问题出在客户端代码中,但我不知道这种行为。如果有人帮助,我将不胜感激。

I am working on google web app. I want to retrieve data based on dropdown selection. I can retrieve data perfectly only on first item selection from dropdown and for the rest i am getting null array received. I have check the server side code by manually calling and its working fine and send data back perfectly. Problem is in client side code but I have no idea of this behavior. I would appreciate if some one help. Thank you in advance.

这里是工作表链接
https://docs.google.com/spreadsheets/d/1yrQjp0_lU3iONW0FK3yCwm79CzD9KUW3Yg92Al5yoAo/edit?usp=sharing

链接到网络应用程序
https://script.google.com/macros/s AKfycbyJdifqDE4NG3dhIsQDQT3f9xKYYfPBL4QXz3p6SZzz3_avdf3b / exec?v = updateevent

这是下拉列表

选择第一个索引项并在警报消息中得到数组

Selection of first index item and got array in alert message

选择第二项并获得空数组

Selection of second item and got null array

当我传递文本时手动到下面的第二和第三项服务器端函数,我得到匹配的行并在数组中检索响应,但是使用客户端时,我得到了空数组。

When I pass the text manually to the below server side function for second and third item i get matching rows and retrieve response in array but using client side i got null array in response.

这是我的服务器端代码:

Here is my server side code:

function GetSelection(title) {
    var ss = SpreadsheetApp.openById("Sheet_ID");
    var sheet = ss.getSheetByName("Event_Info"); 
    var Avals = sheet.getRange("A1:A").getValues();
    var Alast = Avals.filter(String).length;   
    var list  = sheet.getRange("A2:T" + Number(Alast)).getValues();
    Logger.log(list); 
    var values = []; 
    values.pop(); 

    for (var i=0; i < list.length; i++) {
      if (list[i][0].toString().trim().toLowerCase() === title.toString().trim().toLowerCase()) {
          values.push([list[i][0], list[i][1], list[i][2], list[i][3], list[i][4]]); 
          return values;
       }
    }
}

这是我的客户端代码:

    <!DOCTYPE html>
    <html>
      <head>
        <base target="_top">
          <?!= include("CREATEEVENT-CS") ?>
      </head>
      <body onload="addList()">
                <div class="row">
                   <div class="col-25">
                        <label> Event Type </label>
                   </div>
                   <div class="col-75">                   
                        <select id="selectNumber" onchange="jsFunction(this.value)">
                            <option>Choose a number</option>
                        </select>
                   </div>
             </div>

           <?!= include("UPDATEEVENT-JS") ?>
  </body>
</html>

以下是数据检索脚本:

        function jsFunction(value)
        {           
            alert(value);
            google.script.run.withSuccessHandler(getpopuled).GetSelection(value); 
        }

  function getpopuled(dataarray) {
     alert(dataarray);
  }


推荐答案

我的问题已解决。我更改了服务器端代码,因为日期是传递给客户端的受限数据类型,并且将返回null。
所以我将日期转换为数据类型字符串。

My problem is solved. I have change the server side code as date is a restricted data type to pass to client and will return null. So i convert dates to data types string.

function GetSelection(title){
    console.log(title); 
    var ss = SpreadsheetApp.openById("Sheet_ID");
    var sheet = ss.getSheetByName("SheetName"); 
    var Avals = sheet.getRange("A1:A").getValues();
    var Alast = Avals.filter(String).length;   
    var list  = sheet.getRange("A2:T" + Number(Alast)).getValues();
    Logger.log(list); 
    var values = []; 
    values.pop(); 
    for (var i=0; i < list.length; i++){
        if( list[i][0].toString().trim().toLowerCase() === title.toString().trim().toLowerCase() ){
            values.push([ list[i][0], list[i][1], list[i][2], list[i][3],  list[i][4].toString(), list[i][5].toString(),  list[i][6], list[i][7], list[i][8], list[i][9], list[i][10], list[i][11], list[i][12], list[i][13], list[i][14], list[i][15], list[i][16], list[i][17], list[i][18], list[i][19]]); 
       return values;
       }
    }
} 

在客户端,我使用了下面从数据库初始化日期控制,我的问题解决了。

On client side i have used following to intialize date control from database and my problem solved. Thanks to


TheMaster

TheMaster

 document.getElementById("eedate").value = new Date(dataarray[0][5]).toISOString().substr(0, 10);

这篇关于在选择下拉列表时,检索数据为空,但在Google Web应用程序中选择的第一项除外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆