Javascript错误TypeError:无法读取未定义的属性“0”

时间:2015-10-27 20:42:22

标签: javascript google-visualization

我正在尝试使用Google Visualization API绘制图表,只需将api的负载推迟到我正在使用可视化时。

Deferring工作正常,回调也正常,但我无法将数据参数输入其中,出现以下错误。

enter image description here

    addGoogleChartScript: function () {
      var script = document.createElement("script");
      script.src = "http://www.google.com/jsapi?callback=superlist.loadGoogleChart";
      script.type = "text/javascript";

      document.getElementsByTagName("head")[0].appendChild(script);
    },

   loadGoogleChart: function () {
    google.load("visualization", "1", {"callback" : superlist.waitForGVisAndLoad, 'packages':['corechart']});
   },

   waitForGVisAndLoad: function (fn, params) {
    try {
        var data = params[0];
        var text = 'Waiting for Google API to display chart...';
        var h1 = $s('#suplist_item_' + data.id + ' h1');
        if (google && google.visualization && typeof google.visualization.arrayToDataTable == 'function') {
            if (h1.innerHTML == text) h1.innerHTML = h1.getAttribute('prev');
            fn.apply(null, params);
        }
        else {
            if (h1.innerHTML != text) {
                h1.setAttribute('prev', h1.innerHTML.toString());
                h1.innerHTML = text;
            }
            setTimeout(superlist.waitForGVisAndLoad.bind(null, fn, params), 500);
        }
    }
    catch (e) {
        console.error(e)
    }
  },

0 个答案:

没有答案