Couchapp &&事件&&小胡子:我将如何输出子数组?

发布于 2024-11-01 04:28:23 字数 1285 浏览 0 评论 0原文

我正在开发一个演示 couchapp,将一些联系人数据输出到 html 容器。现在,我通过生成 html 并通过 javascript 附加它来完成此操作。

在 CouchDB 中,我可以(我真的很想)使用 Mustache 来更自动地生成此数据,特别是稍后编辑此数据并将其再次存储到数据库中......

现在的 JSON 结构如下所示:

{
   "_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": []
}

我的问题是:

  1. 如何寻址子对象,例如胡子中的“地址”?像这样吗?

    {{#地址}}

    格式化:{{格式化}} 街道地址:{{街道地址}} ...

    {{/addresses}}

  2. 这是否是编辑此数据的良好且可重复使用的方法?在 CouchApps 中如何完成此操作?

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 this 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝天白云 2024-11-08 04:28:23

至于问题1,您也可以使用partials:

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

其中地址将是一个html,其中包含与您在示例中放置的内容相同的内容,并在您的evently语句中分配:

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

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: [ /* ... */ ],
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文