【问题标题】:Angular nested and filtered ng-repeat totals角度嵌套和过滤的 ng-repeat 总计
【发布时间】:2015-10-01 01:01:51
【问题描述】:

我有客户列表和每个客户的订单。它看起来像这样:

  <ul>
    <li ng-repeat="customer in data.customes" | filter:customerFilterFn ">
     {{customer.name}} {{??? total should change depending on nested FILTERED data???}}
      <ul>
        <li ng-repeat="order in customer.orders" | filter:orderFilterFn ">
        {{order.id}} {{order.sum}}
        </li>
      </ul>  
    </li>
  </ul>

如您所见,这两个列表都由它们自己的函数过滤(对于订单,它是一个日期范围)。

对于过滤后的一组订单,获取客户总数的最佳方法是什么?

【问题讨论】:

    标签: angularjs ng-repeat angular-filters


    【解决方案1】:

    您可以将$index 用于ng-repeat 指令。这样您就可以获取每个订单的价值,然后您可以为客户的总数维护一个 $scope 变量。

    【讨论】:

      【解决方案2】:

      实际上,您可以在 ng-repeat 之前使用相同的 orderFilterFn 过滤订单。像这样:http://codepen.io/anon/pen/xwgYZj

      如果性能非常重要,您可以只过滤一次订单:http://codepen.io/anon/pen/bVgLjB

      【讨论】:

        猜你喜欢
        • 2015-09-15
        • 2015-04-19
        • 2015-01-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-25
        • 2015-01-24
        相关资源
        最近更新 更多