You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Jan Pieper <j-...@gmx.net> on 2010/11/28 00:49:48 UTC

is this the "best" way to display a list of documents?

I am new to CouchDB so please be gentle with me :-) I think you guys can help me 
without checking any manuals/guides etc. because it's not very difficult what i 
am searching for.

After importing all my contacts into my own local CouchDB instance I want to set 
up a small HTML interface to show them. So i want to have a list of all contacts 
shown by their names.

- Jessica Alba
- George Clooney
- Charlie Sheen
- ...

## File: <app>/_attachments/index.html ############################

<div id="contacts"></div>
<script type="text/javascript" charset="utf-8">
   $.couch.app(function(app) {
     $("#contacts").evently("contacts", app);
   });
</script>

## File <app>/evently/contacts/_init/data.js ######################

function(data) {
   return {contacts: data.rows.map(row) {
     return {"name": row.value.name};
   })};
}

## File: <app>/evently/contacts/_init/mustache.html ###############

<ul>
   {{#contacts}}
     <li>{{name}}</li>
   {{/contacts}}
</ul>

## File <app>/evently/contacts/_init/query.json ###################

{"view": "contacts", "ascending": true}

## File: <app>/views/contacts/map.js ##############################

function(doc) {
   if (doc.type == "contact") {
     emit(doc.name, doc);
   }
}

## Example document ###############################################

{
   "_id": "...",
   "_rev": "...",
   "type": "contact",
   "name": "Jessica Alba"
}

###################################################################

It's working fine for me but can you please tell me whether this is a good way 
to display a list of documents? Is there another/better way?

with regards,
Jan Pieper