简体   繁体   English

Ember.js中的数组操作

[英]Array operations in Ember.js

Is there a way to perform arithmetic operations such as average or max/mean over a set of array elements, that are loaded into an ArrayController or an ObjectController - this arithmetic operation would be computed again when the array is updated. 有没有一种方法可以对一组数组元素执行算术运算(例如平均值或最大值/平均值),这些数组元素将加载到ArrayController或ObjectController中-在更新数组时将再次计算该算术运算。

Also, how do we obtain the last object from the array in a controller and have the template display this last element? 另外,我们如何从控制器中的数组中获取最后一个对象,并让模板显示该最后一个元素?

Ember does not have specialized functions like mean and avg. Ember没有专门的功能,例如平均值和平均值。 You could easily implement it using a computed property, observing the elements of the array. 您可以使用计算属性轻松实现它,观察数组的元素。 This will give you exactly what you want: recomputed when the array is updated. 这将为您提供所需的确切信息:更新数组时重新计算。

To display the last object, you could use this 要显示最后一个对象,可以使用

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

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