0

如何从 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)
4

1 回答 1

1

你应该像这样调用函数find:

OB.Dal.find(OB.Model.OutletSection, null, function(collection, args){

    alert('Collection variable: '+collection);

}, null, null);
于 2013-07-10T14:01:55.803 回答