【发布时间】:2018-05-18 00:01:01
【问题描述】:
我知道这个问题与回调有关,但我就是无法解决。经过几个小时的研究,我决定发布它。 这是我的代码:
function getTables(callback)
{
connection.query('show tables', function (error, allQueries, fields) {
if (error) throw error;
else{
for(var i=0;i<allQueries.length;i++){
tables.push(allQueries[i].Tables_in_ProyectoFinal);
}
callback(tables);
}
});
}
getTables(function (tables){
for(var i = 0;i < tables.length; i++){
connection.query('show columns from ' + tables[i], function (error, allColumns, fields) {
if (error) throw error;
else{
for(var j = 0;j < allColumns.length; j++){
//columns.push("select " + allColumns[j].Field + " from "+ tables[i]);
console.log("Column: "+allColumns[j].Field+" from table: "+ tables[i]);
}
}
});
}
});
我得到这个结果:
Column: peliculaId from table: undefined
Column: titulo from table: undefined
Column: ano from table: undefined
Column: personaId from table: undefined
Column: nombre from table: undefined
Column: apellido from table: undefined
【问题讨论】:
标签: javascript mysql node.js