提醒由AJAX调用产生的数组值

时间:2013-08-17 03:38:56

标签: ajax google-maps jquery google-maps-api-3

我在尝试提醒ajax调用结果的值时遇到了一些困难。以下代码的工作范围grid.onClick将提醒row的值,但就我而言,我无法弄清楚如何提醒纬度和/或经度的值。

function showGridSalesResult(){
var data = [];
var r_from = $('#min_val').val();
var r_to = $('#max_val').val();
var p_from = $('#from_year').val();
var p_to = $('#to_year').val();
var type = $('#sf3').val();
var municipality = $('#SaleCity').val();

$(document).ready(function(){
jqXHR = $.ajax({
    url: sURL + "search/ajaxSearchResult",
    type: "POST",
    data: 'r_from='+r_from+'&r_to='+r_to+'&p_from='+p_from+'&p_to='+p_to+'&type='+type+'&up_limit='+up_limit+'&low_limit='+low_limit+'&municipality='+municipality,
    dataType: 'json', 
    success: function(json){
        $.each(json, function(i,row){ 
            data[i] = {
                address: row.Address,
                municipality: row.Municipality,
                geoencoded: row.geoencoded,
                latitude: parseFloat(row.geolat),
                longitude: parseFloat(row.geolong)
            };                            
        });

        grid = new Slick.Grid("#myGridMap", data, columns, options);
        grid.invalidate();
        grid.render();
        grid.resizeCanvas();                
        grid.onClick = function (e, row, cell){
            alert(row); // THIS WORKS
            alert(data[row].latitude); // THIS DOES NOT WORK
        }                             
        setMarkers(map, data);
    }    
  });
});
}

有人可以帮我弄清楚如何提醒纬度和经度值吗?

1 个答案:

答案 0 :(得分:1)

检查文档: https://github.com/mleibman/SlickGrid/wiki/Slick.Grid#wiki-getCellFromEvent

你应该使用:

var cell = grid.getCellFromEvent(e);
var latitude = data[cell.row].latitude;
alert(latitude);