你会怎么重复这个

时间:2015-07-20 04:32:01

标签: angularjs ng-repeat

我还想使用ng-repeat显示键“scott”和“bill”及其所有属性值(fullname和age)。

{
    "attributes": {
        "scott": {
            "fullname": "Scott D Man",
            "age": "string"
        },
        "bill": {
            "fullname": "William Shatner",
            "age": "string"
        }
    },
    "id": "HJK321",
    "reportDate": "20150719"
}

4 个答案:

答案 0 :(得分:5)

您可以像这样迭代对象属性:

<div ng-repeat="(key,value) in model.attributes">
    <span>Name : {{key}}</span>
    <span>Full Name : {{value.fullname}}</span>
    <span>Age : {{value.age}}</span>
</div>

plunk

答案 1 :(得分:1)

你可以这样做:

<div ng-app>
  <div ng-controller="ClickToEditCtrl">
    <p>Your Data:</p>
    <ul>
        <li ng-repeat="(key, value) in data.attributes">
            firstname: {{key}}, fullname: {{value.fullname}}, age: {{value.age}}
        </li>
    </ul>
</div>

看看这个jsFiddle:http://jsfiddle.net/vyzsw565/

答案 2 :(得分:1)

    <div ng-repeat='(user, description) in data.attributes'>
      {{user}}
      <div ng-repeat='(key, val) in description'>
        <span>{{key}} : {{val}}</span>
      </div>
      <hr>
    </div>

答案 3 :(得分:0)

查看此工作Jsfiddle

  <div ng-app="mainApp">
     <div ng-controller="mainController">
        <div ng-repeat="d in data">

           Name:      {{d.attributes.scott.fullname}}  ,        
           Age :      {{d.attributes.scott.age}}    

            Name:      {{d.attributes.bill.fullname}}  ,        
            Age :      {{d.attributes.bill.age}}    

        </div>
    </div>
</div>