Couchapp &&事件&&小胡子:我将如何输出子数组?
我正在开发一个演示 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": []
}
我的问题是:
如何寻址子对象,例如胡子中的“地址”?像这样吗?
{{#地址}}
格式化:{{格式化}} 街道地址:{{街道地址}} ...{{/addresses}}
这是否是编辑此数据的良好且可重复使用的方法?在 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:
How do I adress to the sub objects, e.g. for "addresses" in mustache? Like this?
{{#addresses}}
formatted: {{formatted}}
streetAddress: {{streetAddress}}
...{{/addresses}}
Would this be a good and reusable approach to also edit this data? How would this be done in CouchApps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
至于问题1,您也可以使用partials:
其中地址将是一个html,其中包含与您在示例中放置的内容相同的内容,并在您的evently语句中分配:
As for question 1, you may also use partials:
where address will be a html containing the same what you've put in your example, and assigned in your evently statements: