admin管理员组文章数量:1023848
I have an Ember.js ArrayController with a model of People. I'm trying to create a puted property that generates the average of people's weight. It seems like this should be fairly easy, but I'm stuck. Here's my code.
App.PeopleController = Ember.ArrayController.extend({
//each model in the array has a "weight" property
averageWeight: function() {
//I don't know what to do here
}.property('@each.weight')
});
Handlebars code.
{{#each controller}}
{{name}}
{{/each}}
Average weight: {{weight}}
I have an Ember.js ArrayController with a model of People. I'm trying to create a puted property that generates the average of people's weight. It seems like this should be fairly easy, but I'm stuck. Here's my code.
App.PeopleController = Ember.ArrayController.extend({
//each model in the array has a "weight" property
averageWeight: function() {
//I don't know what to do here
}.property('@each.weight')
});
Handlebars code.
{{#each controller}}
{{name}}
{{/each}}
Average weight: {{weight}}
Share
Improve this question
asked Jun 20, 2013 at 18:10
Jarrod NettlesJarrod Nettles
6,3036 gold badges29 silver badges47 bronze badges
1 Answer
Reset to default 8Figured it out. For some reason you need to use 'content.@each' to access the model data inside the puted property.
averageWeight: function(val) {
var weights = this.get('[email protected]').toArray(); //this is the critical part!
weights.forEach(function(val)) {
//calc average here
}
return average;
}.property('@each.weight')
I have an Ember.js ArrayController with a model of People. I'm trying to create a puted property that generates the average of people's weight. It seems like this should be fairly easy, but I'm stuck. Here's my code.
App.PeopleController = Ember.ArrayController.extend({
//each model in the array has a "weight" property
averageWeight: function() {
//I don't know what to do here
}.property('@each.weight')
});
Handlebars code.
{{#each controller}}
{{name}}
{{/each}}
Average weight: {{weight}}
I have an Ember.js ArrayController with a model of People. I'm trying to create a puted property that generates the average of people's weight. It seems like this should be fairly easy, but I'm stuck. Here's my code.
App.PeopleController = Ember.ArrayController.extend({
//each model in the array has a "weight" property
averageWeight: function() {
//I don't know what to do here
}.property('@each.weight')
});
Handlebars code.
{{#each controller}}
{{name}}
{{/each}}
Average weight: {{weight}}
Share
Improve this question
asked Jun 20, 2013 at 18:10
Jarrod NettlesJarrod Nettles
6,3036 gold badges29 silver badges47 bronze badges
1 Answer
Reset to default 8Figured it out. For some reason you need to use 'content.@each' to access the model data inside the puted property.
averageWeight: function(val) {
var weights = this.get('[email protected]').toArray(); //this is the critical part!
weights.forEach(function(val)) {
//calc average here
}
return average;
}.property('@each.weight')
本文标签: javascriptEmberjs computed property with ArrayControllerStack Overflow
版权声明:本文标题:javascript - Ember.js computed property with ArrayController - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745606308a2158747.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论