基于价值Angularjs NG-重复运行总计 [英] Angularjs ng-repeat running total based on value

查看:166
本文介绍了基于价值Angularjs NG-重复运行总计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在angularjs工作,并寻找到正在运行的总保持基于从检索到的数据值。下面code始终返回所有项目的全部总价值。

 < D​​IV NG重复=孩子pItem.childItems |排序依据:'displayOrder'NG-的init =$ parent.totalValue = $ parent.totalValue + child.field [0]。价值>

改变从父范围,孩子清除总价值上的每个重复。因此,值总是等于孩子的价值只是一个项目。

我在找东西返回类似于以下。凡项目1有一个值2,项目2的值3,和项目3值4。


  1. 项目1 2

  2. 项目2 5

  3. 项目3 9


解决方案

尝试这样的事情,这应该做的伎俩:

 < D​​IV
  NG-重复=孩子pItem.childItems |排序依据:'displayOrder'
  NG-的init =child.totalValue = pItem.childItems [$指数1] .totalValue + child.field [0] .value的>
    {{child.field [0] .value的}} {{child.totalValue}}
< / DIV>

所以你基本上是用previous totalvalue的结果总结。

Working in angularjs and looking to keep a running total based on a value retrieved from the data. The following code always returns the full total value for all items.

<div ng-repeat="child in pItem.childItems | orderBy:'displayOrder'" ng-init="$parent.totalValue = $parent.totalValue + child.field[0].value">

Changing that from the parent scope to the child clears the totalValue on each repeat. So the value always equals the child value just for that one item.

I'm looking for something which returns similar to the following. Where Item1 has a value 2, Item2 a value 3, and Item3 a value 4.

  1. Item1 2
  2. Item2 5
  3. Item3 9

解决方案

Try something like this, this should do the trick:

<div 
  ng-repeat="child in pItem.childItems | orderBy:'displayOrder'" 
  ng-init="child.totalValue = pItem.childItems[$index-1].totalValue + child.field[0].value">
    {{child.field[0].value}} {{child.totalValue}}
</div>

So you basically sum with the previous totalValue result.

这篇关于基于价值Angularjs NG-重复运行总计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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