Javascript 无法读取属性';数据表';未定义的

Javascript 无法读取属性';数据表';未定义的,javascript,Javascript,使用jQuery在document ready中调用以下函数时引发错误: searchCity:function(){ var map = this.map, markers = [], input = document.getElementById('pac-input'), dataTable; map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

使用jQuery在document ready中调用以下函数时引发错误:

searchCity:function(){

    var map = this.map,
        markers = [],
        input = document.getElementById('pac-input'),
        dataTable;

    map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

    var searchBox = new google.maps.places.SearchBox(input);

    google.maps.event.addListener(searchBox, 'places_changed', function() {

        var places = searchBox.getPlaces(),
            apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
            url = 'https://api.forecast.io/forecast/',
            lati = places[0].geometry.location.B,
            longi = places[0].geometry.location.k,
            data,
            city = $('.city'),
            summary = $('.summary');

            console.log(places);

        $.getJSON(url + apiKey + "/" + lati + "," + longi + "?callback=?", function(data) {


            console.log(data);

            var dataTable = new google.visualization.DataTable();
            dataTable.addColumn('string', 'hours');
            dataTable.addColumn('number', 'temperature');

            for(var i=0; i<data.daily.data.length; i++){

                  // dataTable.addColumn({type: 'string', role: 'annotation'});
                  dataTable.addRows([
                    ['0'+i,  data.daily.data[i].temperatureMax]
                  ]);
            }

          // Load the Visualization API and the piechart package.
          // google.load('visualization', '1.0', {'packages':['corechart'], callback: weatherAPP.generateGraph});
            var options = { tooltip: {isHtml: true}};
            var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
            chart.draw(dataTable, options);

            city.html('');

            setTimeout( function(){ 
                weatherAPP.slideToCloseSearch();
            }, 500 );

            city.html('').html(places[0].formatted_address);
            summary.html('').html(data.daily.summary);

            if(data.currently.icon = 'clear-day'){
                $('.iconHolder').addClass('icon-sun');
            }
            else if(data.currently.icon = 'rain'){
                $('iconHolder').addClass('icon-rainy');
            }

            $('.temperature').html(data.currently.temperature+ ' <span>F</span>');

            weatherAPP.generateRainVisualEffect();

        });

        if (places.length == 0) {
            return;
        }
        for (var i = 0, marker; marker = markers[i]; i++) {
            marker.setMap(null);
        }

        // For each place, get the icon, place name, and location.
        var bounds = new google.maps.LatLngBounds();

        for (var i = 0, place; place = places[i]; i++) {
            var image = {
                url: 'pin.png'
            };

            var marker = new google.maps.Marker({
                map: map,
                icon: image,
                title: place.name,
                position: place.geometry.location
            });

            markers.push(marker);

            bounds.extend(place.geometry.location);
        }

        map.fitBounds(bounds);

    }); // places_changed

    // Bias the SearchBox results towards places that are within the bounds of the
    // current map's viewport.
    google.maps.event.addListener(map, 'bounds_changed', function() {
        map.setZoom(6);
        var bounds = map.getBounds();
        searchBox.setBounds(bounds);
    });

},

$(document).ready(function(){

     weatherAPP.displayTime();

    weatherAPP.generateMap();

    $('.boom').on('click', function(){

        if(mainWrapper.hasClass(animateLeft)){
            weatherAPP.slideToCloseSearch();
        }else{
            weatherAPP.slideToSearch();
        }

    });

    weatherAPP.searchCity();

});
searchCity:function(){
var map=this.map,
标记=[],
输入=document.getElementById('pac-input'),
数据表;
map.controls[google.maps.ControlPosition.TOP_LEFT].push(输入);
var searchBox=newgoogle.maps.places.searchBox(输入);
google.maps.event.addListener(搜索框,'places_changed',函数(){
var places=searchBox.getPlaces(),
apiKey='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
url='1〕https://api.forecast.io/forecast/',
纬度=位置[0]。几何体。位置。B,
longi=places[0]。geometry.location.k,
数据,
城市=$(“.city”),
摘要=$(“.summary”);
控制台日志(位置);
$.getJSON(url+apiKey+“/”+lati+“,+longi+”?回调=?”,函数(数据){
控制台日志(数据);
var dataTable=new google.visualization.dataTable();
addColumn('string','hours');
dataTable.addColumn('number','temperature');

对于(var i=0;i而言,错误本身是不言自明的。您无法获得未定义对象的属性。因此,它告诉您,在这一行中:

var dataTable = new google.visualization.DataTable();
google
google.visualization
未定义

没有看到其余的代码,我只能猜测是什么导致了问题,但我的假设是,要么谷歌可视化API没有加载。另一种可能是
Google
Google。由于某种原因,可视化
在全局名称空间中不可用。这两个地方我我要开始了

我看到您的代码中有一个带注释的部分,看起来它的目的是加载Google可视化API

如果这是应该加载API的调用,那么取消对它的注释并将其移到DataTable定义之上


如果您仍然无法找出导致问题的原因,请发布更多代码,以便我可以更详细地查看。

错误本身是不言自明的。您无法获得未定义对象的属性。因此,在这一行中,它告诉您:

var dataTable = new google.visualization.DataTable();
google
google.visualization
未定义

没有看到其余的代码,我只能猜测是什么导致了问题,但我的假设是,要么谷歌可视化API没有加载。另一种可能是
Google
Google。由于某种原因,可视化
在全局名称空间中不可用。这两个地方我我要开始了

我看到您的代码中有一个带注释的部分,看起来它的目的是加载Google可视化API

如果这是应该加载API的调用,那么取消对它的注释并将其移到DataTable定义之上


如果您仍然无法找出导致问题的原因,请发布更多代码,以便我可以更详细地查看。

错误本身是不言自明的。您无法获得未定义对象的属性。因此,在这一行中,它告诉您:

var dataTable = new google.visualization.DataTable();
google
google.visualization
未定义

没有看到其余的代码,我只能猜测是什么导致了问题,但我的假设是,要么谷歌可视化API没有加载。另一种可能是
Google
Google。由于某种原因,可视化
在全局名称空间中不可用。这两个地方我我要开始了

我看到您的代码中有一个带注释的部分,看起来它的目的是加载Google可视化API

如果这是应该加载API的调用,那么取消对它的注释并将其移到DataTable定义之上


如果您仍然无法找出导致问题的原因,请发布更多代码,以便我可以更详细地查看。

错误本身是不言自明的。您无法获得未定义对象的属性。因此,在这一行中,它告诉您:

var dataTable = new google.visualization.DataTable();
google
google.visualization
未定义

没有看到其余的代码,我只能猜测是什么导致了问题,但我的假设是,要么谷歌可视化API没有加载。另一种可能是
Google
Google。由于某种原因,可视化
在全局名称空间中不可用。这两个地方我我要开始了

我看到您的代码中有一个带注释的部分,看起来它的目的是加载Google可视化API

如果这是应该加载API的调用,那么取消对它的注释并将其移到DataTable定义之上


如果您仍然无法找出导致问题的原因,请发布更多代码,以便我可以更详细地查看它。

此错误是由于以下原因发生的:

  • 未加载Google可视化库
  • 只需命名回调函数(例如just drawChart),就可以传递对该函数的引用
  • 因此,如果要将参数传递给
    drawChart
    函数,则需要将该调用包装在另一个函数声明中,如下所示:

    google.charts.load('current',{packages:['corechart']});
    setOnLoadCallback(函数(){drawChart(params)});
    
    发生此错误的原因如下:

  • 未加载Google可视化库
  • 只需命名回调函数(例如just drawChart),就可以传递对该函数的引用
  • 因此,如果要将参数传递给
    drawChart
    函数,则需要将该调用包装在另一个函数声明中,如下所示:

    google.chart