使用Tabletop.js,尝试从数组中获取数据

Using Tabletop.js, trying to fetch data from array

本文关键字:数组 获取 数据 Tabletop js 使用      更新时间:2024-02-24

问题

正在尝试从此数组中获取数据,该数组当前包含两个对象。我正在使用Tabletop.js从公共的谷歌电子表格中获取数据,在控制台中收到一个错误,上面写着ReferenceError: object is not defined

控制台

 [Object, Object]/*
    */0: Object
    citation1url: "http://brandonsun.com"
    citation2url: ""
    citation3url: ""
    datesaid: "2/20/2015"
    explanation: ""
    politicianname: "First Name, Last Name"
    rowNumber: 1
    statement: "This is my statement"
    validity: "True, False, Unconfirmed"
    *1: Object
    citation1url: "http://andrewnguyen.ca"
    citation2url: ""
    citation3url: ""
    datesaid: "2/20/2015"
    explanation: ""
    politicianname: "Andrew Nguyen"
    rowNumber: 2
    statement: "I work as a newsroom developer"
    validity: "TRUE"

scripts.js

$(function() {
    window.onload = function() { init() };
      var public_spreadsheet_url = "https://docs.google.com/spreadsheets/d/1glFIExkcuDvhyu5GPMaOesB2SlJNJrSPdBZQxxzMMc4/pubhtml";
      function init() {
        Tabletop.init( { key: public_spreadsheet_url,
                         callback: showInfo,
                         simpleSheet: true } )
      }
      function showInfo(data, tabletop) {
        // alert("Successfully processed!")
        console.log(data);
      }
});

我认为您没有在第二个函数showInfo中定义数据。

我认为最好的方法是为你的桌面模型制作一个变量,比如

var tabletop = Tabletop.init( { key: public_spreadsheet_url, callback: function(data, tabletop) { console.log(data) }, simpleSheet: true });

然后你可以称之为:

$("#myDiv").html(tabletop.data()[1].Statement);