![](/img/trans.png)
[英]How to pass data from React front end Hooks to Express backend
[英]Google App Script WebApp Array doesn't pass from backend to front end
我有一個項目,我使用 Google 表格作為數據庫,並使用 Web 應用程序作為前端。
直到昨天,一個數據數組從后端傳遞到前端,但它不再起作用了。 后端的 logger.log 顯示我們有一個數組。 但是前端永遠不會收到數據。
后端代碼(ssAssessmentLogic 是數據表)
function getDropDownArray(){
var arrDevLogic = ssAssessmentLogic.getDataRange().getValues();
var arrDevLogic =arrDevLogic.filter(function (dataRow) {return dataRow[5] == nutzerSquad})
return arrDevLogic;
前端代碼:
function afterPageLoads(){ //Loads the Dropdowns. First gets the data from the spreadsheet and then populates the dropdowns with the array
google.script.run.withSuccessHandler(afterDataArrayReturned).getDropDownArray();
}
function afterDataArrayReturned(arrDevLogic){ //after the array withe the data came back from the sheet, store the data in a global html variable and pass it to the function to fill the drodown
console.log(arrDevLogic);
arrayOfValues = arrDevLogic.filter(function(r){return true;});
var item = document.getElementById("sdp_ms");
addUniqueDropdown(item, arrayOfValues, 4);
}
在加載 html 頁面時,我收到一個錯誤,即 null 的過濾器不起作用,它顯示控制台日志值為 null。 如果我只運行后端 function 它會為我提供一個包含 260 個項目的數組。
有人可以幫我找出問題嗎?
看起來您要聲明后端代碼變量兩次
function getDropDownArray(){
var arrDevLogic = ssAssessmentLogic.getDataRange().getValues();
**var** arrDevLogic =arrDevLogic.filter(function (dataRow) {return dataRow[5] == nutzerSquad})
return arrDevLogic;
如果您刪除了第二個聲明怎么辦...
function getDropDownArray(){
var arrDevLogic = ssAssessmentLogic.getDataRange().getValues();
arrDevLogic =arrDevLogic.filter(function (dataRow) {return dataRow[5] == nutzerSquad})
return arrDevLogic;
看來我找到了解決方案。 在 Arrays 的數組中,“行數組”中的一些字段是日期,而其他字段是空白的。 似乎 HTML 部分代碼不喜歡它,因為有些 arrays 有日期值,有些是空白的。
謝謝大家的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.