Home  >  Article  >  Web Front-end  >  关于JS 回掉函数的使用_html/css_WEB-ITnose

关于JS 回掉函数的使用_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:45:191039browse

this.query = function(callback){
db.transaction(function (tx) {
  tx.executeSql("select * from transaction_record", [],
function (tx, results) { 
len = results.rows.length;
if(len>0){
for (i = 0; i               var row = results.rows.item(i);
             console.log('id: '+row.id);
             console.log('name: '+row.name);
            }
          if(typeof(callback) == 'function') {callback(results.rows)} 
}else{
if (typeof(callback) == 'function') {callback(false)} //没有数据  
}
},function (tx, error) {
return false;  
console.log('查询失败: ' + error.message);
});
});
}

如上面代码所示:如何调用上面的方法获取返回值???


回复讨论(解决方案)

xxxx.query(function (rows){
// 这里用rows获取返回值
});

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn