Angularjs 使用toArray和groupBy获取ng repeat的原始$index

Angularjs 使用toArray和groupBy获取ng repeat的原始$index,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,我使用toArray和grouptBy进行了2次ng重复,以显示按节分组的数组,每个重复类型作为节头: <div ng-repeat="feed in feeds | groupBy:'type' | toArray:true"> <section layout="row" layout-sm="column" layout-align="center" layout-wrap> <div>{{feed.$key}}</div>

我使用toArray和grouptBy进行了2次ng重复,以显示按节分组的数组,每个重复类型作为节头:

<div ng-repeat="feed in feeds | groupBy:'type' | toArray:true">
  <section layout="row" layout-sm="column" layout-align="center" layout-wrap>
    <div>{{feed.$key}}</div>
    <md-button class="md-raised" ng-class="{'md-primary': !item.hide}"
          ng-click="toggleFeed($index)" ng-repeat="item in feed">
      {{item.name}}
    </md-button>
  </section>

{{feed.$key}}
{{item.name}
我正在尝试获取原始的
$index
,以便更快地访问
$scope.feeds
(使用
$scope.feeds[$index]

现在,
$index
为我提供第二个循环中的索引,
$parent.$index
为我提供父循环(第一个)的索引,但我试图在单击子循环时获取原始索引


有什么想法吗?

正如注释中已经解释的那样,解析所选对象比解析
$index
要好得多。这样,您就不必为索引/对象/数组的更改(例如筛选或排序)而烦恼了

好办法是: 这样,您就可以解析到函数的原始索引:

<div ng-repeat="feed in feeds | groupBy:'type' | toArray:true">
    <section layout="row" layout-sm="column" layout-align="center" layout-wrap>
        <div>{{feed.$key}}</div>
        <md-button class="md-raised" ng-class="{'md-primary': !item.hide}"
                   ng-click="toggleFeed(feed.originalIndex)" ng-repeat="item in feed">
            {{item.name}}
        </md-button>
    </section>
</div>

{{feed.$key}}
{{item.name}

第一种方法简单且性能更高。

不通过索引。传递项目本身:
ng click=“toggleFeed(item)”
这是我当前的解决方案,但是我需要在对象数组中找到该项目……我想知道是否可以直接传递它它是这样工作的……但我最初的问题是:“我正在尝试获取原始的$index,以便更快地访问$scope.feed(使用$scope.feed)。”[$index])“@Galgomedia no m8,由于您必须包含的过程,您无法更快或更高性能地访问它。我将更新我的答案,您将看到您的方法不太好的原因…@Galgomedia检查我的更新。原力现在与您同在。谢谢!我将在数组中找到该对象,谢谢!
$scope.data = [{
    someAttribute: 'value'
},{
    someAttribute: 'value'
},{
    someAttribute: 'value'
},{
    someAttribute: 'value'
},{
    someAttribute: 'value'
},{
    someAttribute: 'value'
},{
    someAttribute: 'value'
}];

$scope.data.forEach(function(item, index) {
    $scope.data[index].originalIndex = index;
});

$scope.feeds = $scope.data;
<div ng-repeat="feed in feeds | groupBy:'type' | toArray:true">
    <section layout="row" layout-sm="column" layout-align="center" layout-wrap>
        <div>{{feed.$key}}</div>
        <md-button class="md-raised" ng-class="{'md-primary': !item.hide}"
                   ng-click="toggleFeed(feed.originalIndex)" ng-repeat="item in feed">
            {{item.name}}
        </md-button>
    </section>
</div>