简体   繁体   English

更新特定嵌套ngRepeat上的limitTo值

[英]Updating the limitTo value on a specific nested ngRepeat

I'm new to AngularJS and having to work on an app that has a section of nested ngRepeats such as this below. 我是AngularJS的新手,因此必须在具有一部分嵌套ngRepeats的应用程序上工作,如下所示。

<div class="title-bar" ng-repeat="orderType in someObj.orderTypes">
    <div class="inner-panel" ng-repeat="status in orderType.statuses">
        <p>{{status.Name}}</p>
        <div class="order-list" ng-repeat="order in status.Orders | limitTo:orderFilterLimit">
            <p>{{order.Stuff}}</p>
        </div>
        <button ng-show="(status.Orders.length > orderFilterLimit)" ng-click="loadMoreOrdersToList()">Load More</button>
    </div>
</div>

The status.Orders list can be quite large at times so I limit it. status.Orders列表有时可能很大,所以我限制了它。 When a user wants to view more data for that specific section (which is enumerated by status ) I add 3 to the orderFilterLimit . 当用户想要查看该特定部分的更多数据(按status枚举)时,我在orderFilterLimit添加3。 The problem is when I do this it is adding 3 to every single .order-list in the .inner-pannel element. 问题是,当我这样做时,它.inner-pannel元素中的.inner-pannel .order-list加3。 Is there a way I can change the orderFilerLimit variable based on an id or class of the element it's attached to? 有没有一种方法可以根据其所附加元素的ID或类来更改orderFilerLimit变量?

For context here is a super simple snippet of what loadMoreOrdersToList() is doing. 对于上下文,这里是loadMoreOrdersToList()正在执行的操作的超简单代码段。 https://jsbin.com/vapucixesa/1/edit?js https://jsbin.com/vapucixesa/1/edit?js

No need of declare the orderFilterLimit inside controller, You should have scope variable inside ng-repeat itself so that it ng-repeat element will have separate copy of orderFilterLimit because ng-repeat create a child scope on each iteration. 无需在控制器内部声明orderFilterLimit ,您应该在ng-repeat自身内部具有scope变量,以便ng-repeat元素将具有orderFilterLimit单独副本,因为ng-repeat会在每次迭代时创建子范围。

Markup 标记

<div class="title-bar" ng-repeat="orderType in someObj.orderTypes" ng-init="orderFilterLimit = 3">
    <div class="inner-panel" ng-repeat="status in orderType.statuses">
        <p>{{status.Name}}</p>
        <div class="order-list" ng-repeat="order in status.Orders | limitTo:orderFilterLimit">
            <p>{{order.Stuff}}</p>
        </div>
        <button ng-show="(status.Orders.length > orderFilterLimit)" ng-click="orderFilterLimit = orderFilterLimit + 3">Load More</button>
    </div>
</div>

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

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