Your attempt to use the result synchronously, that is, your access result until it is determined (in fact, in your example code it is not undefined, its an empty array), although I expect that this is because you moved the declaration from its original position trying to figure out what's happening.
Try this modified example: -
$.Model.extend('Article', { findAll : function(params, success, error){ db.transaction(function(tx) { tx.executeSql('select * from contents', [], function(tx, rs) { var result = []; for(var i=0; i<rs.rows.length; i++) { var row = rs.rows.item(i) result.push({ id: row['id'], title: row['title'], body: row['body'] }); } success(result); }); }); } }); Article.findAll({}, function(result) {
Article.findAll () is now an asynchronous function, and its callback (closure) gets the results.
source share