I would suggest using a custom filter such as this:
(我建议使用这样的自定义过滤器:)
app.filter('reverse', function() {
return function(items) {
return items.slice().reverse();
};
});
Which can then be used like:
(然后可以这样使用:)
<div ng-repeat="friend in friends | reverse">{{friend.name}}</div>
See it working here: Plunker Demonstration
(看到它在这里工作: 柱塞演示)
This filter can be customized to fit your needs as seen fit.
(该过滤器可以根据您的需要进行定制,以适应您的需求。)
I have provided other examples in the demonstration.(我在演示中提供了其他示例。)
Some options include checking that the variable is an array before performing the reverse, or making it more lenient to allow the reversal of more things such as strings.(一些选项包括在执行反向操作之前检查变量是否为数组,或者使它更宽松以允许反向执行更多操作,例如字符串。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…