changeset 83:b95fc8f8a344

Added section on using findRow().
author Atul Varma <varmaa@toolness.com>
date Mon, 20 Apr 2009 16:51:40 -0700
parents 90854d908f0b
children dbe68e5af673
files tutorial.html
diffstat 1 files changed, 29 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/tutorial.html	Mon Apr 20 16:41:20 2009 -0700
+++ b/tutorial.html	Mon Apr 20 16:51:40 2009 -0700
@@ -78,8 +78,7 @@
 
 <p>The output placed in the <tt>author-keyed-view</tt> element is:</p>
 
-<div class="example-output" id="author-keyed-view">
-</div>
+<div class="example-output" id="author-keyed-view"></div>
 
 <p>As you can see, BrowserCouch essentially iterated over all of the
 blog posts, passing each one to <tt>map()</tt>, along with an
@@ -103,7 +102,7 @@
     },
     finished: function(result) {
       displayInElement(result, 'author-titles-view');
-      tryMyView();
+      tryViewWithFindRow();
     }
   });
 }
@@ -111,8 +110,7 @@
 
 <p>The output is as follows:</p>
 
-<div class="example-output" id="author-titles-view">
-</div>
+<div class="example-output" id="author-titles-view"></div>
 
 <p>The <tt>reduce()</tt> mechanism is a bit harder to
 understand. Essentially, BrowserCouch takes all the rows generated by
@@ -128,6 +126,32 @@
 <p>The <tt>reduce()</tt> function is called for each unique key, and
 its return value is the value for its key in the final view.</p>
 
+<p>Once you've got a view, you can use the view's <tt>findRow()</tt>
+method to find the first row whose key matchest (or is closest to) the
+one you provide.  For example:</p>
+
+<div class="example-code">
+function tryViewWithFindRow() {
+  blogDb.view({
+    map: function(doc, emit) {
+      emit(doc.author, doc.title);
+    },
+    reduce: function(keys, values) {
+      return values;
+    },
+    finished: function(result) {
+      var rowIndex = result.findRow('Thunder');
+      displayInElement(result.rows[rowIndex], 'author-find-row-view');
+      tryMyView();
+    }
+  });
+}
+</div>
+
+<p>The output for this one is:</p>
+
+<div class="example-output" id="author-find-row-view"></div>
+
 <h1>Now You Try!</h1>
 
 <p>If your eyes are crossed right now, no worries&mdash;it took me a