【问题标题】:Nested Ng-Repeat and object properties嵌套的 Ng-Repeat 和对象属性
【发布时间】:2014-04-01 12:42:28
【问题描述】:

我有一个包含许多对象的对象。 objects 属性是用户名属性,包含一个对象,该对象的属性是组,值为 true 或 false。

ReportModel.Taxonomy = {
    Authenticated Users: Object
    Test Group 1: " ✓ "
    Test Group 2: " ✓ "
    Test Group 3: " - "
    Test Group 4: " - "
    Test Group 5: " ✓ "
    Test Group 6: " - "
    Test Group 7: " - "
    Test Group 8: " ✓ "
    TestGroup: " - "
Test Users: Object
    Test Group 1: " - "
    Test Group 2: " - "
    Test Group 3: " - "
    Test Group 4: " ✓ "
    Test Group 5: " - "
    Test Group 6: " ✓ "
    Test Group 7: " - "
    Test Group 8: " - "
    TestGroup: " - "
}

我一直在尝试使用 ng-repeat 创建一个表,其中每一行在标题之后提供用户名(第 1 列)和每个组的结果:

    <table>
        <tr class="reportHeader" >
            <th>USERS</th>
            <th ng-repeat="group in ReportModel.groups">{{group.name}}</th>
        </tr>
        <tr ng-repeat="user in ReportModel.taxonomy">
            <td>{{user.name}}</td>
            <td ng-repeat="user.userGroups"></td>
        </tr>
    </table>

鉴于 Taxonomy 对象的设置方式,我无法弄清楚如何使用 ngRepeat。

【问题讨论】:

    标签: javascript html angularjs angularjs-ng-repeat


    【解决方案1】:

    这是你想要做的: How can I iterate over the keys, value in ng-repeat in angular

    例如:

    <table>
        <tr ng-repeat="(key, user) in ReportModel.taxonomy">
            <td>{{key}}</td>
            <td ng-repeat="(key, group) in user"></td>
        </tr>
    </table>
    

    【讨论】:

    • 是的。哇,原来如此。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    相关资源
    最近更新 更多