我采用了棱角分明的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分数)等等。这可以做到吗?
我采用了棱角分明的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分数)等等。这可以做到吗?
我会使用自定义过滤器和$index
迭代var (av可重复的ng-repeat)。它应该提供您需要的格式。这里有一种方法:
输出样本:
<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>
您可以使用$指数和其追加
<th ng-repeat="x in data.items[0].bf_val " >
<div style="width: 70px" >{{$index+1}} BF Score</div>
</th>
<th ng-repeat="x in data.items[0].bf_val track by $index" >
<div style="width: 70px" > {{$index + 1}} BF Score</div>
</th>
,如果你想拥有第二
,你垫3日已添加的逻辑在那里