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

时间:2015-02-20 18:53:41

标签: javascript jquery arrays object tabletop.js

问题

尝试从此数组中获取数据,该数组当前包含两个对象。我使用Tabletop.js从公共Google电子表格中获取数据,在控制台中显示错误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);
      }
});

1 个答案:

答案 0 :(得分:0)

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

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

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

然后你可以打电话给它:

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