2016-12-13 27 views
1

我採用了棱角分明的js有什麼辦法來聲明和增量角度JS

<th ng-repeat="x in data.items[0].bf_val " > 
 
\t \t <div style="width: 70px" > BF Score</div> 
 
\t </th>

的NG-重複功能現在,而不是僅僅BF得分的NG-重複裏面的變量。對於每一行我都想要一個數字。像第一排應該讀取(第一BF分數),第二排作爲(第二BF分數)等等。這可以做到嗎?

回答

1

我會使用自定義過濾器和$index迭代var (av可重複的ng-repeat)它應該提供您需要的格式。這裏有一種方法:

DEMO

輸出樣本:

Ordinal Screenshot

<div ng-app="ordinalApp"> 
    <section ng-controller="mainController"> 
     <div ng-repeat="item in items"> 
      {{ ($index + 1) | ordinal }} BF Score 
     </div> 
    </section> 
</div> 

<script> 

var app = angular.module("ordinalApp", []); 
// what ur looking for 
//found here: http: //forums.shopify.com/categories/2/posts/29259 

app.filter('ordinal', function($filter) { 
    var suffixes = ["th", "st", "nd", "rd"]; 
    return function(n) { 
    var s = ["th", "st", "nd", "rd"], 
     v = n % 100; 
    return n + (s[(v - 20) % 10] || s[v] || s[0]); 
    }; 
}); 

app.controller('mainController', function($scope) { 
    $scope.items = [{ 
    bf_val: 1, 
    bf_score: 30 
    }, { 
    bf_val: 2, 
    bf_score: 40 
    }, { 
    bf_val: 3, 
    bf_score: 50 
    }, { 
    bf_val: 4, 
    bf_score: 60 
    }]; 
}); 
</script> 
1

您可以使用$指數和其追加

<th ng-repeat="x in data.items[0].bf_val " > 
     <div style="width: 70px" >{{$index+1}} BF Score</div> 
</th> 

DEMO

0
<th ng-repeat="x in data.items[0].bf_val track by $index" > 
    <div style="width: 70px" > {{$index + 1}} BF Score</div> 
</th> 
,如果你想擁有第二

,你墊3日已添加的邏輯在那裏

相關問題