我遇到过很多类似的问题,但还没有确切地了解我希望如何工作。这是一个不是我的作品,我刚刚修改了它:http://plnkr.co/edit/ntlZjxnV6we9Je2OZnLL?p=preview
您可以在data.json文件中看到一周中有一天的列表。我已经设法显示了星期二从tue
开始的日子,但它没有显示tue
索引之前的其他日子,即sun
和mon
,它们应该显示在sat
下。有没有办法显示tue
索引之前的剩余天数?
好吧,我想我明白你想要什么了。这是一个有效的解决方案。
函数listElementsAfterIndex
获取一个集合和用于拆分集合的索引。
控制器
$scope.name = data.name;
$scope.children = data.children;
$scope.listElementsAfterIndex = function(collection, index) {
var head = collection.slice(0, index + 1);
var tail = collection.slice(index + 1);
return tail.concat(head);
}
查看
<body ng-controller="MainCtrl">
<h2>Days</h2>
<div ng-repeat="child in listElementsAfterIndex(children,1)">
{{child.data}}
</div>
<br> ^ Displaying rest of the days here now under `sat` which are `sun` and `mon`
</body>