Display most important information from a JSON file

2

How do I display only some of the most important information in a list as in the example below?

{
    "userId": 1,
    "id": 1,
    "title": "DRF - Delegacia de Roubos e Furtos",
    "endereco": "Praca Maua, 5 - Centro",
    "tel":"2233-2701",
    "long":"-22.896893,0",
    "lat":"-43.181976"
},

It does not matter if you use AngularJS, JSON, JavaScript. I'd just like to know how do I pull just one information to avoid repetitions. For example: how to display in a location just the name, address, and phone number of the location for users to see?

    
asked by anonymous 07.10.2015 / 04:01

2 answers

3

Your question explicitly mentions 'submission'. So the answer is easy - display only the fields you need. Example:

function SampleController($scope) {
  $scope.dados = [
    {
      "userId": 1,
      "id": 1,
      "title": "DRF - Delegacia de Roubos e Furtos",
      "endereco": "Praca Maua, 5 - Centro",
      "tel":"2233-2701",
      "long":"-22.896893,0",
      "lat":"-43.181976"
    }];
}
<html ng-app>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script></head><body><divng-controller="SampleController">
      <table>
        <tr>
          <th>
            ID
          </th>
          <th>
            Local
          </th>
        </tr>
        <tr ng-repeat='i in dados'>
          <td>{{i.id}}</td>
          <td>{{i.title}}
          </td>
        </tr>
      </table>
    </div>
  </body>
</html>

When you run this code, notice that only two properties are displayed.

    
07.10.2015 / 04:29
2
<html ng-app="app">
<head>CDN ANGULAR JS</head>
<body ng-controller="Crtl">
{{user.id}}
</body>
</html>


angular.module('app', []).controller('Ctrl', function($scope) {
 $scope.user = [
                "userId": 1,
                "id": 1,
                "title": "DRF - Delegacia de Roubos e Furtos",
                "endereco": "Praca Maua, 5 - Centro",
                "tel":"2233-2701",
                "long":"-22.896893,0",
                "lat":"-43.181976"
                ];
});
    
07.10.2015 / 04:17