简体   繁体   中英

How to display this list in AngularJS

    {
  "code": 2001,
  "message": "valid devices",
  "results": [
    {
      "event_type": "active_devices",
      "receivedtimestamp": "Thu, 12 Mar 2015 04:35:05 GMT",
      "sendtimestamp": "2015-03-19T18:18:00+0000",
      "source_ip_address": "192.168.1.4",
      "summary_hostname": [
        "",
        "android-74643bd169c2eb2c",
        "Windows-Phone"
      ],
      "summary_ip": [
        "",
        "192.168.10.111",
        "192.168.10.103"
      ],
      "summary_mac": [
        "",
        "e0:cb:ee:50:27:78",
        "78:92:3e:62:01:f8"
      ],
      "summary_start": [
        "",
        "2015/03/19 18:15:13",
        "2015/03/19 18:14:14"
      ]
    }
  ],
  "status": 200
}

I have this data.

I have a variable $scope.data = results; , and I'm using ng-repeat to display this data. How to display this using ng-repeat ? i want to display summary_hostname and summary_mac

The ngRepeat directive instantiates a template once per item from a collection. Each template instance gets its own scope, where the given loop variable is set to the current collection item, and $index is set to the item index or key.

But you have used one element of the array. Through ngRepeat you can display only summary_hostname, summary_ip, summary_mac, summary_start. Because arrays discreet than 1 line.

If you just want to show the array of one line use

<pre>{{data}}</pre>

If the array is more than one line, but you have brought only part of the array, you can print it so

<div ng-repeat="row in data">
    {{row.event_type}},{{row.source_ip_address}}
    <div ng-repeat="ip in row.summary_ip">{{ip}}</div>
</div>

If you want to display only summary_hostname and summary_mac here is how you can accomplish that:

<div ng-controller="MyCtrl">

    <div ng-repeat="host in data.results[0].summary_hostname">
        {{host}}
    </div>

    <div ng-repeat="mac in data.results[0].summary_mac">
        {{mac}}
    </div>

</div>

Fiddle

you want to display only summary_hostname and summary_mac,ok here these things appear JSON in the form of array right,so your trying to get total array.please try this

<div ng-controller="MyCtrl">
  <div ng-repeat="host in data">
    {{host[0].summary_hostname}}
  </div>

  <div ng-repeat="mac in data">
    {{mac[0].summary_mac}}
  </div>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM