请帮我解决这个问题:
我在访问nodeJS嵌套client.query
中的变量时遇到问题这是代码:
client.query("SELECT distinct(nip) as nip, nama from history_talenta", function(err,rows_final){
var inner_counter=0;
var kumulatif_talenta='';
var naikgrade=false;
var finalJSON = [];
for(var p=0; p < rows_final.length; p++) {
client.query("SELECT h.nip, COUNT(*) as jumlah, h.talenta FROM history_talenta h, bobot_talent b where h.nip = '"+rows_final[p].nip+"' and h.talenta = b.talent GROUP BY h.talenta ORDER BY b.bobot DESC", function(err,rows_jlh_talenta){
for(var k=0; k<rows_jlh_talenta.length; k++){
if(inner_counter<1){
kumulatif_talenta += rows_jlh_talenta[k].jumlah+" "+rows_jlh_talenta[k].talenta;
}else{
kumulatif_talenta += ", "+rows_jlh_talenta[k].jumlah+" "+rows_jlh_talenta[k].talenta;
}
client.query("SELECT count(syarat) as syarat FROM syarat_naik_grade where syarat = '"+kumulatif_talenta+"'", function(err,result_check){
if(result_check[0].syarat>0){
naikgrade = true;
//array
var myObj2 = {
"nip" : rows_final[p].nip, **<== nip is undefined**
"nama" : rows_final[p].nama, **<== nama is undefined**
"perolehan_talenta" : kumulatif_talenta,
"is_naik_grade_normal" : naikgrade
};
// Send Result to JSON
finalJSON.push( myObj2 );
}
});
inner_counter++;
}
kumulatif_talenta='';
inner_counter = 0;
});
// Reset variable
kumulatif_talenta="";
inner_counter=0;
naikgrade=false;
}
// Send to browser
//console.log(JSON.stringify(finalJSON, null, 4));
res.render('pages/hasilchecknaikgrade',{ data2 : JSON.stringify(finalJSON, null, 4), data : req.session.user, datarole : req.session.role, moment : moment } );
});
问题是,如何访问&#34; nip&#34;和&#34; nama&#34;变量,来自内部嵌套的client.query吗?
&#34; nip&#34;和&#34; nama&#34; var是第一个查询/顶级client.query的返回值。
谢谢