Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented Data.Collection#range.

  • Loading branch information...
commit 94f390831da4da98e806425a7a21aa4c11db5f23 1 parent d96536c
Michael Aufreiter authored
Showing with 10 additions and 2 deletions.
  1. +10 −2 data.js
View
12 data.js
@@ -208,7 +208,6 @@
// Returns all objects matching a particular query object
query: function(qry) {
-
function toArray(v) {
return _.isArray(v) ? v : [v];
}
@@ -218,6 +217,7 @@
_.find(qry, function(value, property) {
var val = property === "type" ? obj.types : obj.properties[property];
+ if (property === "_id") val = obj._id;
var matchedValues = _.intersect(toArray(value), toArray(val));
if (matchedValues.length === 0) {
matched = false;
@@ -537,6 +537,14 @@
return this.length > 0 ? this.objects[this.length-1] : null;
},
+ range: function(start, end) {
+ var result = Data.Collection.create(this.type, []);
+ for(var i=start; i<=end && i<this.objects.length; i++) {
+ result.add(this.at(i));
+ }
+ return result;
+ },
+
// Performs an intersection with the given *collection*
intersect: function(collection) {
var that = this,
@@ -592,4 +600,4 @@
};
}
});
-})();
+})();
Please sign in to comment.
Something went wrong with that request. Please try again.