0
我有一個好奇的問題。Array will not fill out
我從數據庫中提取行並將其插入數組。但Array.push()
將無法正常工作。
來源
var donations_data = [];
/* Get Donations */
instance.server.db.query("SELECT * FROM `donations` WHERE `userid`='" + instance.user_data.userid + "' AND `visible`='1' ORDER BY `date` DESC LIMIT 10", function(error, rows, fields) {
if(rows.length > 0) {
_.each(rows, function (entry, index) {
console.log(">>>>>>>>>>>>>>>>>>>>>");
console.log(entry);
console.log(">>>>>>>>>>>>>>>>>>>>>");
donations_data.push({
username: entry.from_username,
note: entry.note,
timestamp: entry.date,
amount: entry.amount,
currency: entry.currency,
currency_symbol: '?',
transaction_id: entry.transaction_id,
paypal_email: entry.from_paypal_email
});
});
}
});
console.log("==================================");
console.log(donations_data);
console.log("==================================");
輸出
>>>>>>>>>>>>>>>>>>>>>
{ id: 4,
userid: 1,
from_username: 'user 2',
from_paypal_email: '[email protected]',
transaction_id: '12345',
status: 'COMPLETED',
note: 'No Message',
date: 1386012587,
amount: '5.00',
cent_amount: 0,
an_dt: '',
currency: 'EUR',
visible: 1,
date2: Mon Dec 02 2013 20:29:47 GMT+0100 (CET),
new: 0 }
>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>
{ id: 3,
userid: 1,
from_username: 'USer 1',
from_paypal_email: '[email protected]',
transaction_id: '23ewqs',
status: 'COMPLETED',
note: 'Das ist ein Test',
date: 1386012427,
amount: '5.00',
cent_amount: 0,
an_dt: '',
currency: 'EUR',
visible: 1,
date2: Mon Dec 02 2013 20:27:07 GMT+0100 (CET),
new: 0 }
>>>>>>>>>>>>>>>>>>>>>
==================================
[]
==================================
你能告訴我爲什麼陣列就不會成交?數據將打印出來,因此必須工作...
好吧,我明白了,但我如何檢查查詢是否完成? – 2014-08-29 10:15:46