我正在将 Cordova 和 Angular 用于一个小型 Web 应用程序。下面是实现过程:
LogsModel
被建造queryLogs()
叫做getLogsArray()
被调用——此时,即使在函数定义中,也console.log(this.logs['0'])
返回undefined
. 我不明白为什么。
LogsModel.prototype.logs = {};
LogsModel.prototype.getLogsArray = function (){
console.log(this.logs['0']);
return this.logs;
};
LogsModel.prototype.queryLogs = function (){
var self = this;
function getFromDb (tx){
tx.executeSql('SELECT * FROM DEMO',[],querySuccess,self.query_fail);
}
function querySuccess(tx,results){
var len = results.rows.length;
for(var i = 0; i < len; i++){
var log = {
verb: results.rows.item(i).verb
};
self.logs[i]= {
verb: results.rows.item(i).verb
};
}
}
this.db = window.openDatabase("Database","1.0","Cordova Demo",200000);
this.db.transaction(getFromDb,self.transaction_fail);
};