使用不同索引值的ng-repeat

时间:2015-07-17 13:37:01

标签: javascript arrays angularjs ng-repeat

我正在开发一个页面,我需要显示一些框(使用ng-repeat),其中包含频道信息以及显示位置(哪些城​​市)。

我面临的问题是当我重复第二次重复重复时:

<table class="table table-condensed" ng-init="nitsCh = [objsCh[$index].nit]">

这应该得到第一个ng-repeat的$ index并创建一个新的数组,其中显示了通道的位置。它确实如此。但是,当我使用这个数组应用第二个ng-repeat时,它不能正常工作。

说,我的html看起来像这样:

    <<div class="box box-solid box-default" ng-repeat="(indexO, objCh) in objsCh track by indexO" ng-if="indexO%4==0  && indexO<=10"> 
      <div class="box-header"> 
        <div class="pull-left"> 
          <img src="dist/img/channels/{{ objsCh[indexO].pic }}" data-toggle="tooltip" title="" data-original-title="Alterar logo do canal"> 
          <h3 class="box-title">{{ objsCh[(indexO)].name }}</h3> 
        </div> 
        <div class="box-tools pull-right"> 
          <button class="btn btn-box-tool" data-toggle="tooltip" title="" data-original-title="Adicionar ou Remover NIT"><i class="fa fa-plus"></i></button> 
        </div> 
      </div> 
      <div class="box-body"> 
        <table class="table table-condensed" ng-init="nitsCh = [objsCh[indexO].nit]"> 
          <tbody> 
            <tr> 
              <th style="width: 10px">#</th> 
              <th>Nit</th> 
            </tr> 
            <tr ng-repeat="(indexN,nitCh) in nitsCh track by indexN"> 
              <td>{{ objsCh[(indexO + 1)].nit[indexN].num }}</td>
              <td>{{ objsCh[(indexO + 1)].nit[indexN].name }}</td>
            </tr> 
          </tbody>
        </table> 
      </div> 
    </div>

JS文件如下所示:

var app = angular.module('appApp', []);

app.controller(&#39; ctrlApp&#39;,功能($ scope,$ http){

var url="includes/exibChNit.php";

$http.get(url).success( function(response) {
    all = response;
    $scope.objsCh = all.channels;
}); 

});

json文件(php创建)看起来像这样:

{
"channels": [
    {
        "id": "1",
        "sid": "1",
        "name": "Channel",
        "pic": "channel.jpg",
        "crc32": "A1g423423B2",
        "special": "0",
        "url": "",
        "key": "",
        "type": "",
        "city": [
            {
                "num": "1",
                "name": "S�o Paulo"
            },
            {
                "num": "2",
                "name": "Rio de Janeiro"
            }
        ]
    },
    {
        "id": "2",
        "sid": "2",
        "name": "CHannel 1",
        "pic": "channel.jpg",
        "crc32": "A1F5534234B2",
        "special": "0",
        "url": "",
        "key": "",
        "type": "",
        "city": [
            {
                "num": "1",
                "name": "S�o Paulo"
            },
            {
                "num": "2",
                "name": "Rio de Janeiro"
            }
        ]
    }
]

}

提前致谢!

致以最诚挚的问候,

0 个答案:

没有答案