如何在ng-repeat中设置变量的值?

时间:2016-08-02 06:02:38

标签: angularjs

我有这个ng-repeat:

<div ng-repeat="row in phs.phrasesView = (phs.phrases | orderBy:phs.phrasesOrderBy[phs.phrasesOrderById].key:phs.phrasesSortDirectionId == 1)"

    ***
    *** I want something here to set the value of pos ***
    *** based on array1.findIndex(v => v.phraseId == 'def') + 1; ***
    ***                        
 >
    <div>{{ phs.phrases[pos].phraseId }} </div>
    <div>{{ phs.phrases[pos].keyword }} </div>

我有这些数据:

var phs.phrases = [{
  "phraseId": "abc",
  "keyword": "bb",
  "posId": 1
}, {
  "phraseId": "def",
  "keyword": "bb",
  "posId": 1
}, ];

我想要做的是找到行的位置。我不能使用$ index,因为我想找到位置并在排序后显示它。

我知道我可以使用此代码来查找pos,但是如何设置它以使此代码适用于ng-repeat的每一行?

var pos = array1.findIndex(v => v.phraseId == 'def') + 1;

1 个答案:

答案 0 :(得分:1)

将每个对象的位置存储在对象内:

{{ getPositionOf(row) }}

或(但他的效率低得多),调用函数找到ng-repeat中的位置:

{{1}}
相关问题