diff options
| author | Trygve Laugstøl <trygvis@inamo.no> | 2012-07-03 10:47:42 +0200 | 
|---|---|---|
| committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-07-03 10:47:42 +0200 | 
| commit | c8758323adeecea8271ad950e5e6fabc6b34f2fc (patch) | |
| tree | 6b04443b5d4906f676e7cacd8d818c21a4d913ce | |
| parent | 50f66cc93167fe45894c4bc9f3908190d5bd2821 (diff) | |
| download | collection_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.js | 14 | 
1 files changed, 10 insertions, 4 deletions
| @@ -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) { | 
