查找当前数组项的兄弟

时间:2015-06-30 22:16:43

标签: javascript angularjs

这当前列出了所有出现的数组。我只想显示与父数组中当前项关联的数组。

EG:而不是列出第一位置,第二位置,第三位置。我希望它只列出第一个位置的第一个位置,第二个位置的第二个位置等等。我错过了什么?

http://plnkr.co/edit/ilgOZzIy2axSi5Iy85C7

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

App.controller('locationAccordionCtrl', function ($scope) {

  $scope.locations = [
    {
      "siteName":"First Location",
      "locationsList":['First Location 1', 'First Location 2', 'First Location 3']
    },
    {
      "siteName":"Second Location",
      "locationsList":['Second Location 1', 'Second Location 2', 'Second Location 3']
    },
    {
      "siteName":"Third Location",
      "locationsList":['Third Location 1', 'Third Location 2', 'Third Location 3']
    }
  ];
});

HTML:

<div ng-controller="locationAccordionCtrl">
    <div ng-repeat="location in locations">

      {{location.siteName}}

      <div ng-repeat="location in locations">
        <ul>
          <li ng-repeat="listOfLocations in location.locationsList track by $index">
            {{listOfLocations}}
          </li>
        </ul>
      </div>

    </div><!-- /row -->
</div>

1 个答案:

答案 0 :(得分:3)

你应该改变:

<div ng-repeat="location in locations">
    <ul>
        <li ng-repeat="listOfLocations in location.locationsList track by $index">
            {{listOfLocations}}
        </li>
    </ul>
</div>

对此:

<ul>
    <li ng-repeat="listOfLocations in location.locationsList track by $index">
        {{listOfLocations}}
    </li>
</ul>