2012-07-23 77 views
0

我使用websql數據庫成功存儲了我的記錄,並在讀取它時回到第一次返回undefined時第二次返回實際值。從web sql將數據讀入變量

myDB.transaction(function(transaction) { 
    transaction.executeSql('SELECT * FROM tempTelemedicine', [], function(transaction, output) { 
    if (output != null && output.rows != null) { 
     for (var i = 0; i < output.rows.length; i++) { 
     var record = output.rows.item(i); 
     this.date = record.date; 
     this.firstName = record.firstName; 
     this.lastName = record.lastName; 
     this.address = record.address; 
     this.clinic = record.clinic; 
     this.mobile_no = record.mobile_no; 
     this.age = record.age; 
     this.age_afa = record.age_afa; 
     this.number_oa = record.number_oa; 
     this.number_oailsm = record.number_oailsm; 
     this.months_sla = record.months_sla; 
     this.sex = record.sex; 
     this.predisposing = record.predisposing; 
     this.color = record.color; 
     this.stiff = record.stiff; 
     this.shaking = record.shaking; 
     this.tongue = record.tongue; 
     this.incontinent = record.incontinent; 
     this.head = record.head; 
     this.eyes = record.eyes; 
     this.communicates = record.communicates; 
     this.weakness = record.weakness; 
     this.comment = record.comment; 
     alert("DATA SET"); 
     $('#lbUsers').append('<br>'+"new data"+' '+ record.patientId 
     + ' ' + record.date + ' ' + record.firstName + ' ' + record.lastName 
     + ' ' + record.address + ' ' + record.clinic + ' ' + record.mobile_no 
     + ' ' + record.age + ' ' + record.age_afa + ' ' + record.number_oa 
     + ' ' + record.number_oailsm + ' ' + record.months_sla + ' ' 
     + record.sex + ' ' + record.predisposing + ' ' + record.color 
     + ' ' + record.stiff + ' ' + record.shaking + ' ' + record.tongue 
     + ' ' + record.incontinent + ' ' + record.head + ' ' + record.eyes 
     + ' ' + record.communicates + ' ' + record.weakness + ' ' + record.comment); 
     } 
    } 
    }); 
} 

回答

3

這是因爲執行JavaScript的異步模式。
Web瀏覽器和JavaScript共享單個線程來渲染和處理代碼,在這種情況下,變量在分配值之前使用。