我正在使用Appcelerator构建应用程序。 我使用Backbone从数据库中获取数据。
所以我构建了这段代码来从数据库中获取数据:
var collection = Alloy.createCollection("SocialHistoryDAO");
collection.fetch();
现在我想申请此馆藏的地方。所以我使用这段代码:
collection.where(id : 5);
然后此代码有效,但现在我想应用此过滤器:
“WHERE ID!= 5”;
可以这样做吗?
编辑: 这是我的SocialHistoryDAO模型:
exports.definition = {
config: {
columns: {
"ID": "INTEGER PRIMARY KEY AUTOINCREMENT",
"IdOmnia": "INTEGER",
"DateStart": "text",
"DateEnd": "text",
"Quantity": "decimal",
"Code": "text",
"CodeSystem": "text",
"DisplayName": "text",
"DisplayNameTarget": "text",
"UnityMeasure": "text",
"StateID": "INTEGER"
},
adapter: {
type: "sql",
collection_name: "SocialHistoryDAO",
idAttribute: "ID"
}
},
extendModel: function(Model) {
_.extend(Model.prototype, {
// extended functions and properties go here
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
destroyAll : function(opt) {
var db = Ti.Database.open(this.config.adapter.db_name);
db.execute("DELETE FROM " + this.config.adapter.collection_name);
db.close();
this.models = [];
if (!opt || !opt.silent) { this.trigger("reset"); }
return this;
}
});
return Collection;
}
};
答案 0 :(得分:1)
如果您正在使用Backbone,那么您还使用了Underscore(或LoDash)。
这可以使用以下任一方式完成:
var newArray = _.filter(collection.models, function(model) { return model.get('ID') != 5; });
或
var newArray = _.reject(collection.models, function(model) { return model.get('ID') == 5; });