summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-07-03 10:47:42 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-07-03 10:47:42 +0200
commitc8758323adeecea8271ad950e5e6fabc6b34f2fc (patch)
tree6b04443b5d4906f676e7cacd8d818c21a4d913ce
parent50f66cc93167fe45894c4bc9f3908190d5bd2821 (diff)
downloadcollection_json.js-c8758323adeecea8271ad950e5e6fabc6b34f2fc.tar.gz
collection_json.js-c8758323adeecea8271ad950e5e6fabc6b34f2fc.tar.bz2
collection_json.js-c8758323adeecea8271ad950e5e6fabc6b34f2fc.tar.xz
collection_json.js-c8758323adeecea8271ad950e5e6fabc6b34f2fc.zip
o Making sure each query has a data array.
-rw-r--r--index.js14
1 files changed, 10 insertions, 4 deletions
diff --git a/index.js b/index.js
index c0d0378..bcc6927 100644
--- a/index.js
+++ b/index.js
@@ -8,15 +8,21 @@ function fromObject(root) {
root.collection = _.isObject(root.collection) ? root.collection : {};
var c = root.collection;
c.version = _.isString(c.version) ? c.version : "1.0";
- c.items = _.isArray(c.items) ? c.items : [];
- c.links = _.isArray(c.links) ? c.links : [];
- c.queries = _.isArray(c.queries) ? c.queries : [];
- c.templates = _.isArray(c.templates) ? c.templates : [];
+ c.items = _.isArray(c.items) ? c.items : [];
_.each(c.items, function(item) {
item.links = _.isArray(item.links) ? item.links : [];
});
+ c.links = _.isArray(c.links) ? c.links : [];
+
+ c.queries = _.isArray(c.queries) ? c.queries : [];
+ _.each(c.queries, function(query) {
+ query.data = _.isArray(query.data) ? query.data : [];
+ });
+
+ c.templates = _.isArray(c.templates) ? c.templates : [];
+
// TODO: make un-enumerable
root.mapItemData = function(f) {
return _.map(this.collection.items, function(item) {