查找托管对象数组的总和
我在从数组中获取简单的总成本时遇到了一个大问题!
我有一个名为 currentCost 的实体,它包含两个属性:costAmount 和 costDesc。我将其绑定到数组控制器,当我向该实体添加项目或从该实体删除项目时,没有任何问题。问题是从 costAmount
属性获取总成本并将其显示在文本字段中。
我想我必须将所有 costAmount
获取到另一个数组并获取它们的总和,但似乎我不知道该怎么做!最好的方法是什么?
先感谢您。
I have a big problem with taking a simple Total Cost from an array!
I have an entity called currentCost
, it contains two attributes: costAmount
and costDesc
. I bind it to an array controller and I have no problem when I add and remove items to and from this entity. The problem is to get the Total Cost from the costAmount
attributes and show it in a text field.
I think I have to fetch all costAmount
s to another array and take the total of them, but it seems I don't know how to do this! What is the best approach ?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将文本字段绑定到数组控制器,并指定
@sum.costAmount
作为关键路径。Bind the text field to the array controller and specify
@sum.costAmount
as the key path.