javascript - Problems retrieving separate Document in Map-Function -
i've written little function results based on 2 search terms user can make. terms are: owner & path
of folder.
the map function down below works far gives me right folder when user looks bob
& holiday
. unfortunately elfe if
part doesn't work, want retrieve files document. if separate both if
's works. why not in combination? :-)
map-function:
function(doc) { if (doc.type == 'folder') { emit([doc.owner, doc.path], null); } else if (doc.files) { (var in doc.files) { emit(doc.owner, {_id: doc.files[i]}); } } }
documents:
// folder { "_id": "folder.abc", "name": "holiday", "type": "folder", "owner": "bob", "path": "\\holiday", "files": [ "file.123" ] } // files { "_id": "file.123", "name": "hawaii.jpg", "type": "file", }
search query:
[snip]?key=["bob","\\holiday"]&include_docs=true
result:
{ "total_rows":4, "offset":2, "rows":[ { "id":"folder.abc", "key":[ "bob", "\\holiday" ], "value":null, "doc":{ "_id":"folder.abc", "name":"holiday", "type":"folder", "owner":"bob", "path":"\\holiday", "files":[ "file.123" ] } } ] }
unfortunately elfe if part doesn't work, want retrieve files document. if separate both if's works. why not in combination? :-)
this doesn't work because javascript doesn't have elseif
keyword. using else if
equivalent to:
if (doc.type === 'folder') { ... } else { if (doc.files) { ... } }
see: mdn if...else
Comments
Post a Comment