为什么尽管查询后面有代码,但查询在代码之前运行。它打印一个空数组,然后在查询函数中执行所有操作。这是javascript中的正常行为吗?如何让我的程序正确流动?
var soda = require('soda-js');
var consumer = new soda.Consumer('data.seattle.gov');
var data_rows = [];
var query = consumer.query()
.withDataset('c3ri-wwcn')
.limit(5)
.getRows()
.on('success', function(rows) { console.log(rows);
console.log("here");
data_rows = rows;
console.log(data_rows);
for (item in data_rows) {
console.log(data_rows[item]);
};
})
.on('error', function(error) { console.error(error); });
console.log(data_rows);
for (item in data_rows) {
console.log(item);
};