0

Tenho um arquivo .json e preciso listar os itens dele da seguinte forma.

Empresa 1

  • Valor 1

Empresa 1

  • Valor 2

Empresa 2

  • Valor 1

Empresa 2

  • Valor 2

Abaixo segue a estrutura do meu arquivo .json

{
"market": {
    "company": [
        {
            "name": "Petrobras",
            "logo": "https://s29.postimg.org/lnt4mtp2f/petrobras.png",
            "stock": [
                {
                    "name": "PETR4",
                    "openingvalue": "22.45",
                    "actualvalue": "22.54"
                },
                {
                    "name": "PETR3",
                    "openingvalue": "28.10",
                    "actualvalue": "28.05"
                }
            ]
        },
        {
            "name": "VALE",
            "logo": "https://s29.postimg.org/u8mgdzz8n/vale.png",
            "stock": [
                {
                    "name": "VALE4",
                    "openingvalue": "17.65",
                    "actualvalue": "17.32"
                },
                {
                    "name": "VALE3",
                    "openingvalue": "21.11",
                    "actualvalue": "21.32"
                }
            ]
        },
        {
            "name": "ITAU",
            "logo": "https://s29.postimg.org/jul61dxk7/itau.png",
            "stock": [
                {
                    "name": "ITUB4",
                    "openingvalue": "8.7",
                    "actualvalue": "8.89"
                },
                {
                    "name": "ITUB3",
                    "openingvalue": "12.73",
                    "actualvalue": "12.91"
                }
            ]
        },
        {
            "name": "BRADESCO",
            "logo": "https://s29.postimg.org/58u5d50rr/bradesco.png",
            "stock": [
                {
                    "name": "BBDC4",
                    "openingvalue": "6.29",
                    "actualvalue": "6.08"
                },
                {
                    "name": "BBDC3",
                    "openingvalue": "8.37",
                    "actualvalue": "8.42"
                }
            ]
        },
        {
            "name": "AMBEV",
            "logo": "https://s29.postimg.org/tmsfkrxuv/ambev.png",
            "stock": [
                {
                    "name": "ABEV4",
                    "openingvalue": "7.65",
                    "actualvalue": "7.43"
                },
                {
                    "name": "ABEV3",
                    "openingvalue": "9.78",
                    "actualvalue": "10.02"
                }
            ]
        },
        {
            "name": "OI",
            "logo": "https://s29.postimg.org/ejbbdsht3/oi.png",
            "stock": [
                {
                    "name": "OIBR4",
                    "openingvalue": "3.94",
                    "actualvalue": "3.67"
                },
                {
                    "name": "OIBR3",
                    "openingvalue": "5.09",
                    "actualvalue": "5.01"
                }
            ]
        },
        {
            "name": "GOL",
            "logo": "https://s29.postimg.org/8478k04rr/gol.png",
            "stock": [
                {
                    "name": "GOLL4",
                    "openingvalue": "11.26",
                    "actualvalue": "11.07"
                },
                {
                    "name": "GOLL3",
                    "openingvalue": "16.70",
                    "actualvalue": "16.93"
                }
            ]
        },
        {
            "name": "AMERICANAS",
            "logo": "https://s29.postimg.org/69ue29hrb/americanas.png",
            "stock": [
                {
                    "name": "LAME4",
                    "openingvalue": "1.85",
                    "actualvalue": "1.88"
                },
                {
                    "name": "LAME3",
                    "openingvalue": "2.57",
                    "actualvalue": "2.59"
                }
            ]
        },
        {
            "name": "SMILES",
            "logo": "https://s29.postimg.org/hfyce2nmv/smiles.png",
            "stock": [
                {
                    "name": "SMLE4",
                    "openingvalue": "15.33",
                    "actualvalue": "15.12"
                },
                {
                    "name": "SMLE3",
                    "openingvalue": "18.64",
                    "actualvalue": "18.78"
                }
            ]
        }
    ]
  }
}

Abaixo segue a estrutura do meu HTML

<uib-accordion close-others="oneAtATime">
    <div uib-accordion-group class="panel-default" is-open="isOpen" template-url="group-template.html" ng-repeat="lista in main.listas.market.company">
      <div ng-repeat="subLista in lista.stock">
      <uib-accordion-heading>
        <div class="pull-left">
          <img src="{{lista.logo}}" class="img-responsive pull-left">
          <span class="title">{{lista.name}} <span>- {{subLista.name}}</span></span>
        </div>
        <div class="pull-right details">
          <span>{{isOpen ? 'Ocultar' : 'Ver'}} detalhes da ação</span>
          <i class="pull-right glyphicon" ng-class="{'glyphicon-menu-up': isOpen, 'glyphicon-menu-down': !isOpen}"></i>
        </div>
      </uib-accordion-heading>
      <div class="row">
        <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2">
          <span class="status green">Abertura:</span> {{subLista.openingvalue}}
        </div>
        <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2">
          <span class="status red">Atual:</span> {{subLista.actualvalue}}
        </div>
        <div class="col-lg-2 col-lg-offset-4 col-md-2 col-sm-2 col-xs-2" ng-controller="ModalController as $ctrl">
          <button type="submit" class="btn btn-default pull-right" ng-click="$ctrl.open('md')">Vender</button>
        </div>
      </div>
      </div>
  </uib-accordion>

Da forma como eu fiz os 2 valores de cada empresa estão aparecendo dentro dessa empresa, da seguinte forma.

Empresa 1

  • Valor 1

  • Valor 2

Preciso fazer com que o nome da empresa repita e com os valores diferentes.

1 Resposta 1

0

Na verdade o seu código tem um erro relacionado a essa tag:

<div class="col-lg-2 col-lg-offset-4 col-md-2 col-sm-2 col-xs-2" ng-controller="ModalController as $ctrl">
    <button type="submit" class="btn btn-default pull-right" ng-click="$ctrl.open('md')">Vender</button>
</div>

que ng-controller="ModalController as $ctrl", por algum motivo não foi mencionado na pergunta. Retirando essa parte, funcionou, sendo que o resto está praticamente correto.

Vejo o código rodando logo abaixo:

var app = angular.module('app', [])
  .controller('ctrl', ['$scope',
    function($scope) {

      $scope.main = {
        listas: {
          "market": {
            "company": [{
              "name": "Petrobras",
              "logo": "https://s29.postimg.org/lnt4mtp2f/petrobras.png",
              "stock": [{
                "name": "PETR4",
                "openingvalue": "22.45",
                "actualvalue": "22.54"
              }, {
                "name": "PETR3",
                "openingvalue": "28.10",
                "actualvalue": "28.05"
              }]
            }, {
              "name": "VALE",
              "logo": "https://s29.postimg.org/u8mgdzz8n/vale.png",
              "stock": [{
                "name": "VALE4",
                "openingvalue": "17.65",
                "actualvalue": "17.32"
              }, {
                "name": "VALE3",
                "openingvalue": "21.11",
                "actualvalue": "21.32"
              }]
            }, {
              "name": "ITAU",
              "logo": "https://s29.postimg.org/jul61dxk7/itau.png",
              "stock": [{
                "name": "ITUB4",
                "openingvalue": "8.7",
                "actualvalue": "8.89"
              }, {
                "name": "ITUB3",
                "openingvalue": "12.73",
                "actualvalue": "12.91"
              }]
            }, {
              "name": "BRADESCO",
              "logo": "https://s29.postimg.org/58u5d50rr/bradesco.png",
              "stock": [{
                "name": "BBDC4",
                "openingvalue": "6.29",
                "actualvalue": "6.08"
              }, {
                "name": "BBDC3",
                "openingvalue": "8.37",
                "actualvalue": "8.42"
              }]
            }, {
              "name": "AMBEV",
              "logo": "https://s29.postimg.org/tmsfkrxuv/ambev.png",
              "stock": [{
                "name": "ABEV4",
                "openingvalue": "7.65",
                "actualvalue": "7.43"
              }, {
                "name": "ABEV3",
                "openingvalue": "9.78",
                "actualvalue": "10.02"
              }]
            }, {
              "name": "OI",
              "logo": "https://s29.postimg.org/ejbbdsht3/oi.png",
              "stock": [{
                "name": "OIBR4",
                "openingvalue": "3.94",
                "actualvalue": "3.67"
              }, {
                "name": "OIBR3",
                "openingvalue": "5.09",
                "actualvalue": "5.01"
              }]
            }, {
              "name": "GOL",
              "logo": "https://s29.postimg.org/8478k04rr/gol.png",
              "stock": [{
                "name": "GOLL4",
                "openingvalue": "11.26",
                "actualvalue": "11.07"
              }, {
                "name": "GOLL3",
                "openingvalue": "16.70",
                "actualvalue": "16.93"
              }]
            }, {
              "name": "AMERICANAS",
              "logo": "https://s29.postimg.org/69ue29hrb/americanas.png",
              "stock": [{
                "name": "LAME4",
                "openingvalue": "1.85",
                "actualvalue": "1.88"
              }, {
                "name": "LAME3",
                "openingvalue": "2.57",
                "actualvalue": "2.59"
              }]
            }, {
              "name": "SMILES",
              "logo": "https://s29.postimg.org/hfyce2nmv/smiles.png",
              "stock": [{
                "name": "SMLE4",
                "openingvalue": "15.33",
                "actualvalue": "15.12"
              }, {
                "name": "SMLE3",
                "openingvalue": "18.64",
                "actualvalue": "18.78"
              }]
            }]
          }
        }
      };
    }
  ]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>


<div ng-app="app" ng-controller="ctrl">
  <uib-accordion close-others="oneAtATime">
    <div uib-accordion-group class="panel-default" is-open="isOpen" template-url="group-template.html" ng-repeat="lista in main.listas.market.company">
      <div ng-repeat="subLista in lista.stock">            
        <uib-accordion-heading>
          <div class="pull-left">
            <img src="{{lista.logo}}" class="img-responsive pull-left">
            <span class="title">{{lista.name}} <span>- {{subLista.name}}</span></span>
          </div>
          <div class="pull-right details">
            <span>{{isOpen ? 'Ocultar' : 'Ver'}} detalhes da ação</span>
            <i class="pull-right glyphicon" ng-class="{'glyphicon-menu-up': isOpen, 'glyphicon-menu-down': !isOpen}"></i>
          </div>
        </uib-accordion-heading>
        <div class="row">
          <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2">
            <span class="status green">Abertura:</span> {{subLista.openingvalue}}
          </div>
          <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2">
            <span class="status red">Atual:</span> {{subLista.actualvalue}}
          </div>
          <div class="col-lg-2 col-lg-offset-4 col-md-2 col-sm-2 col-xs-2">
            <button type="submit" class="btn btn-default pull-right" ng-click="$ctrl.open('md')">Vender</button>
          </div>
        </div>
      </div>
    </div>
  </uib-accordion>
</div>

Possar ser a falta da imprementação do controller ModalController que esteja faltando no seu código, ou falta da inclusão do que contenha esse código.

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .