开发者

Couchapp && Evently && Mustache: How would I output subarrays?

I am working on a demo couchapp to output some contact data to a html-container. Right now, I am doing this by generating the html and appending it via javascript.

In CouchDB I could (I would really like) to be using mustache for generating this more automatically, especially for the later editing thi开发者_运维问答s data and storing it to the db again...

The JSON structure for now looks like this:

{
   "_id": "478d86edbbd94bbe627f3ebda300dfb1",
   "_rev": "1-b6b1582f41f38c7a1d3ce43514e97371",
   "accounts": [],
   "activities": [],
   "addresses": [
      {
         "formatted": "B 31\nHeilbronn   74081",
         "streetAddress": "B 31\nHeilbronn   74081",
         "type": "Privat",
         "home": false,
         "primary": false,
         "work": false
      },
      {
         "formatted": "Strasse \nHeilbronn   74081",
         "streetAddress": "Strasse\nHeilbronn   74081",
         "type": "Work",
         "home": false,
         "primary": false,
         "work": false
      }
   ],
   "books": [],
   "cars": [],
   "contactID": 46,
   "date_created": "2011-02-07T19:42:07.813+01:00",
   "date_modified": "2011-02-07T19:42:07.813+01:00",
   "displayName": "Adac Adac",
   "emails": [],
   "foods": [],
   "heroes": []
}

My questions are:

  1. How do I adress to the sub objects, e.g. for "addresses" in mustache? Like this?

    {{#addresses}}

    formatted: {{formatted}} streetAddress: {{streetAddress}} ...

    {{/addresses}}

  2. Would this be a good and reusable approach to also edit this data? How would this be done in CouchApps?


As for question 1, you may also use partials:

{{#addresses}}
    {{>address}}
{{/addresses}}

where address will be a html containing the same what you've put in your example, and assigned in your evently statements:

partials: [ /* ... */ ],
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜