Mercurial > browser-couch
diff tutorial.html @ 74:4450be5d1b2f
Added reduce() example to the tutorial.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 20 Apr 2009 13:37:10 -0700 |
parents | 8f0b18026782 |
children | 17ce8b6be452 |
line wrap: on
line diff
--- a/tutorial.html Mon Apr 20 13:31:32 2009 -0700 +++ b/tutorial.html Mon Apr 20 13:37:10 2009 -0700 @@ -60,6 +60,7 @@ }, finished: function(result) { displayInElement(result, 'author-keyed-view'); + tryAnotherView(); } }); } @@ -70,6 +71,31 @@ <div class="example-output" id="author-keyed-view"> </div> +<p>We could also try creating another view that adds a +<tt>reduce()</tt> function to group together the blog post titles with +the authors:</p> + +<div class="example-code"> +function tryAnotherView() { + blogDb.view({ + map: function(doc, emit) { + emit(doc.author, doc.title); + }, + reduce: function(keys, values) { + return values; + }, + finished: function(result) { + displayInElement(result, 'author-titles-view'); + } + }); +} +</div> + +<p>The output is as follows:</p> + +<div class="example-output" id="author-titles-view"> +</div> + <script src="js/ext/jquery.js"></script> <script src="js/browser-couch.js"></script> <script src="js/tutorial.js"></script>