javascriptの次の関数から戻りオブジェクトを取得するにはどうすればよいですか -
function find(model, whereClause, success, error, args) {
var tableName = model.prototype.tableName,
propertyMap = model.prototype.propertyMap,
sql = 'SELECT * FROM ' + tableName,
params = null,
appendWhere = true,
firstParam = true,
k, v;
if (db) {
// websql
if (whereClause && whereClause._whereClause) {
whereClause.sql = ' ' + whereClause._whereClause;
} else {
whereClause = getWhereClause(whereClause, propertyMap);
}
sql = sql + whereClause.sql;
params = whereClause.params;
if (model.prototype.propertyMap._idx) {
sql = sql + ' ORDER BY _idx ';
}
if (model.prototype.dataLimit) {
sql = sql + ' LIMIT ' + model.prototype.dataLimit;
}
db.readTransaction(function (tx) {
tx.executeSql(sql, params, function (tr, result) {
var i, collectionType = OB.Collection[model.prototype.modelName + 'List'] || Backbone.Collection,
collection = new collectionType(),
len = result.rows.length;
if (len === 0) {
success(collection, args);
} else {
for (i = 0; i < len; i++) {
collection.add(transform(model, result.rows.item(i)));
}
if(success){
success(collection, args);
} else {
return collection
}
}
}, error);
});
} else {
// localStorage
throw 'Not implemented';
}
}
関数 find() を呼び出すと、db.readTransaction の tx.executeSql() 内の変数コレクションが返されます。
OB.Dal.find(OB.Model.OutletSection, null, null, null, null)