使用Angular处理项目,并且好奇是否有一种“特定于角度”的方法来实现这一目标。
我基本上想要从数组中的特定项开始检索数据,例如第3个。 如果angular提供任何类型的方法或过滤器,你会在html中看到我很好奇。
HTML
<div ng-controller="bracketsController">
<div ng-repeat="bracket in brackets | limitTo: 2" class="bracket-container left" >
<div>{{bracket.brackets.single.contestant1}}</div>
<div>{{bracket.brackets.single.contestant2}}</div>
</div>
<div ng-repeat="bracket in brackets | limitTo: 2 SOME **Angular FILTER TO START AT 3**" class="bracket-container right" >
<div>{{bracket.brackets.single.contestant1}}</div>
<div>{{bracket.brackets.single.contestant2}}</div>
</div>
</div>
JS
var bracketsapp = angular.module('bracketsApp', []);
bracketsapp.controller('bracketsController', function($scope){
$scope.brackets = [
{
"brackets": {
"single": {
"contestant1": "john doe",
"contestant2": "jane doe"
}
}
},
{
"brackets": {
"single": {
"contestant1": "john doe",
"contestant2": "jane doe"
}
}
},
{
"brackets": {
"single": {
"contestant1": "john doe",
"contestant2": "jane doe"
}
}
},
{
"brackets": {
"single": {
"contestant1": "john doe",
"contestant2": "jane doe"
}
}
},
{
"brackets": {
"single": {
"contestant1": "john doe",
"contestant2": "jane doe"
}
}
}
]
});
感谢您的任何提示或建议。
答案 0 :(得分:1)
您可以直接在数组上使用.slice方法:
<div ng-repeat="bracket in brackets.slice(3)" class="bracket-container right" >
除此之外,他们目前正在讨论下一版本的角度来支持这个过滤器。您可以在此处跟随:https://github.com/angular/angular.js/issues/5355
答案 1 :(得分:1)
您可以创建自己的过滤器,在此处提及:Filter results 6 through 10 of 100 with ng-repeat in AngularJS
app.filter('slice', function() {
return function(arr, start, end) {
return (arr || []).slice(start, end);
};
});
<div ng-repeat="bracket in brackets | slice:3:2">{{item}}</div>