简体   繁体   English

AngularJS ng-repeat 索引限制?

[英]AngularJS ng-repeat index limit?

is there a way to represent a value based on specific data and put a limit on it?有没有办法根据特定数据表示值并对其进行限制?

i wanna show only 3 value of span but this is show up 4 span.我只想显示 3 个跨度值,但这是显示 4 个跨度。

help me帮我

this is my example code这是我的示例代码

<div ng-repeat="list in checkDate">
   <span ng-if="list.day == '20200120'">{{list.time}} {{list.day}}</span>
</div>

$scope.checkDate = [{
            day: '20200120',
            time: '09:30'
        }, {
            day: '20200119',
            time: '10:30'
        }, {
            day: '20200120',
            time: '11:30'
        },
        {
            day: '20200109',
            time: '12:30'
        },
        {
            day: '20200125',
            time: '13:30'
        },
        {
            day: '20200120',
            time: '14:30'
        },
        {
            day: '20200120',
            time: '15:30'
        }
    ]

The main reason is why ng-if is inside ng-repeat .主要原因是为什么ng-ifng-repeat里面。

So if you try with only limitTo it will not work.因此,如果您仅尝试使用limitTo ,它将无法正常工作。

First you have to filter record based on your desired date and than you have to apply limitTo to ng-repeat .首先,您必须根据所需日期filter记录,然后必须将limitTo应用于ng-repeat

Solution - ng-repeat="list in checkDate | filter: {day: '20200120'} | limitTo:3"解决方案 - ng-repeat="list in checkDate | filter: {day: '20200120'} | limitTo:3"

try this - https://jsfiddle.net/qkvf2ojh/试试这个 - https://jsfiddle.net/qkvf2ojh/

It's because ng-if is applied after limitTo filter producing result.这是因为在limitTo过滤器产生结果之后应用了ng-if In this case, use filter instead of ng-if directive.在这种情况下,请使用filter而不是ng-if指令。 For example,例如,

   <div ng-repeat="list in checkDate | filter: {day: '20200120'} | limitTo:3">
       <span>{{list.time}} {{list.day}}</span>
   </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM