作为查询结果修改的函数之外的变量的访问值 - JavaScript

时间:2014-02-19 23:51:29

标签: javascript google-visualization google-fusion-tables

如何在修改其值的函数之外使用全局变量numRes的修改值? 当我在修改后访问它时,我只得到初始值。

How do I change the value of a global variable inside of a functionHow do I return the response from an asynchronous call? 问题描述了类似的东西,但它们没有帮助。

提前感谢您的帮助。

google.load('visualization', '1'); 
// ...

var query = new google.visualization.Query(
    'http://www.google.com/fusiontables/gvizdata?tq='  + queryText);

numRes = 0;
query.send(function(response) {
    numRes = response.getDataTable().getNumberOfRows();
    console.log(numRes + " results are found - inside query.send"); // correct
    });

// how to get the same value as three lines above?
console.log(numRes + " results are found"); // not correct, gives 0
// setTimeout(console.log(numRes + " results are found - after timeout"), 10000); // does not help

foo = numRes;
// ... code with foo

0 个答案:

没有答案