JavaScript(phonegap):如何在构造函数中的方法之间传递变量?
var myCodesDb = {
myCodes: null,
//...
loadMyCodes1: function (){
db=window.openDatabase("Database","1.0","myCodes",200000);
var query = 'SELECT * FROM my_table';
db.transaction(function(tx) {tx.executeSql(query),[]},
this.errorDbCallBack,
function(tx, results) { this.myCodes = results.rows });
},
loadMyCodes2: function (){
db=window.openDatabase("Database","1.0","myCodes",200000);
var query = 'SELECT * FROM my_table';
db.transaction(function(tx) {tx.executeSql(query),[]},
this.errorDbCallBack,
this.loadMyCodesSuccess);
},
loadMyCodesSuccess: function (tx, results){
this.myCodes = results.rows;
},
};
不幸的是,这两种方法(loadMyCodes1
和loadMyCodesSuccess
)都是results
未定义的值(当然还有myCode
)。
答案 0 :(得分:0)
我不确定你到底想要做什么,但你有一个有多种方法的课程。您可以使用以下内容:
this.methodName.bind(this, x, y, z and so on...)