AngularJS limitTo由过去的2条记录 [英] AngularJS limitTo by last 2 records

查看:185
本文介绍了AngularJS limitTo由过去的2条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否AngularJS 过滤器的组合 订单 ,或 limitTo NG-重复 模仿 _。最后 在UnderscoreJS <? / p>

解决方案

如果我理解你的问题正确,我认为这个小提琴会做。

对于这个数据:

  $ scope.items = {[排序:1,名称:第一},
                【分页:1,名称:'二'},
                【分页:3,名称:'三'},
                {排序:4,名称:最后一个}];

如果您不想竟对数组进行排序,并只取数组的最后两个项目的是(如下划线的最后一个),你可以尝试一个负的限制(这将显示三,最后):

 &LT; D​​IV NG重复=项中的项目| limitTo:-2&GT;

另外请注意,你可以链中的过滤器一起这样的例子排序反向的数据并采取2项(这将显示最后,第三个):

 &LT; D​​IV NG重复=项中的项目|排序依据:'排序':真| limitTo:2&GT;

Can a combination of AngularJS filter, order, or limitTo for ng-repeat mimic the _.last in UnderscoreJS?

解决方案

If I'm understanding your question correctly I think this fiddle would do it.

For this data:

$scope.items = [{sort: 1, name: 'First'}, 
                {sort: 2, name: 'Second'}, 
                {sort: 3, name: 'Third'}, 
                {sort: 4, name:'Last'}];

If you don't want to actually sort the array and just take the last two items of the array as is (like underscore's last) you can try a negative limit (this would show Third, Last):

<div ng-repeat="item in items | limitTo:-2">

Also note you can chain the filters together like this example sorting the data in reverse and taking 2 items (this would show Last, Third):

<div ng-repeat="item in items | orderBy:'sort':true | limitTo:2">

这篇关于AngularJS limitTo由过去的2条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆