使用Angular和MongoDB迭代子容器

时间:2013-03-06 14:51:16

标签: mongodb angularjs

我很想知道使用angular迭代mongodb以获取给定客户的所有域的最佳方法。

这是来自MongoDB的我的JSON:

    {
"_id": {
    "$oid": "513568dae4b08eabdba2eb63"
},
"name": "Sofa King",
"contactPrimaryName": "Richard Cranium",
"contactPrimaryPhone": "410 555-1212",
"contactPrimaryEmail": "me@mysite.com",
"PrimaryAddress": "123 Any Street\nApt. 17",
"contactPrimaryCity": "Nashville",
"contactPrimaryState": "TN",
"contactPrimaryZip": "22222",
"site": "http://www.mysite.com",  //ignore, replacing with domains
"domains": [
    {
        "url": "http://www.mysite.com",
        "ns1": "ns1.mydns.com",
        "ns2": "ns2.mydns.com",
        "registered": "2011-01-01",
        "expires": "2014-01-01"
    },
    {
        "url": "http://www.myother.com",
        "ns1": "ns1.mydns.com",
        "ns2": "ns2.mydns.com",
        "registered": "2012-02-02",
        "expires": "2015-02-02"
    }
]

我知道我可以通过以下方式获取客户详细信息:

    <tr ng-repeat="customer in customers | filter:search | orderBy:'name'">
    <td><a href="{{customer.site}}" target="_blank">{{customer.name}}</a></td>
    <td>{{customer.contactPrimaryName}}</td>
    <td>{{customer.contactPrimaryPhone}}</td>
    <td>{{customer.contactPrimaryEmail}}</td>

但我不确定如何获取给定客户的域名网址。

我的目标是在一个页面上创建一个客户列表,其中包含一个按钮,用于查看该客户的域。查看给定客户的域时,可以添加域。

1 个答案:

答案 0 :(得分:4)

您应该能够为当前客户迭代“domains”数组:

<tr ng-repeat="customer in customers | filter:search | orderBy:'name'">
...
    <td>
        <div data-ng-repeat="domain in customer.domains">
            // Do stuff in here with the domain for that customer
        </div>
    </td>
</tr>