使用 Google 可视化工具和 Javascript 根据响应设置数组

Set arrays from response using Google visualization tools & Javascript

我试图将两个单独的数组(headers & 行)设置为等于我正在做的查询的响应。

let dataProp = {}
// I make the query
var query2 = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1xEz5wfWSwXbAgWhgvJxfxSDhNGf5w8hqVpAFbbAViEo/gviz/tq?tqx=out:json&sheet=Sheet2')

// I send the query to a function to be handled
query2.send(handleQueryResponse2)
function handleQueryResponse2(response) {

    // I want to inspect the response (shown below in image)
    console.log(response.getDataTable())

    data2 = response.getDataTable()
    dataProp.table2 = { rows: [...data2.fg] }

    // let's put this loop aside (this sanitizes the content in same data type.)
    for (let i = 0; i < data2.fg.length; i++) {
      let tempRow = [];
      for (let j = 0; j < data2.fg[i].c.length; j++) {
        tempRow[j] = cleanRowsContent(dataProp.table2.rows[i].c[j])
      }
      dataProp.table2.rows[i] = tempRow
    }
  }

控制台中查询的响应:

问题:如代码所示,我想获取 headers 和如下所示的行,但值“If”和“fg”随更新而变化(变为“Fg” & "hg" 等等...) 而且我经常需要检查我的代码是否仍在工作...有人可以解释我如何解决这个问题吗?

更多上下文:我正在使用 Google 可视化工具(进行多个查询),因为它比传统的 jquery api 轻 97%格式可用

首先,如果你想设置变量的属性 --> dataProp
需要使用对象 ({}),而不是数组 ([])

let dataProp = {};

下一步,而不是尝试直接从数据中访问数据 table,
尝试将数据 table 转换为 json,
然后拿起你想要的碎片...

google.charts.load('current', {
  packages: ['corechart']
}).then(function () {

  let dataProp = {};
  var query2 = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1xEz5wfWSwXbAgWhgvJxfxSDhNGf5w8hqVpAFbbAViEo/gviz/tq?tqx=out:json&sheet=Sheet2');

  query2.send(handleQueryResponse2);
  function handleQueryResponse2(response) {

    // convert data table to json
    data2 = JSON.parse(response.getDataTable().toJSON());

    // get rows
    dataProp.table2 = data2.rows;

    // get columns
    dataProp.table3 = data2.cols;

    console.log(JSON.stringify(dataProp));

  }

});