I want to bind parent (arrayController) property with children (itemController). The binding works only when I'm setting the properites in childController like this.set('foo', property), instead using computed properties.
App.IndexController = Ember.ArrayController.extend({
numberOfAllLetters: (function() {
return this.getEach('lettersNo').reduce(function(prev, curr){
return prev + curr
});
}).property('@each.lettersNo'),
numberOfAllLetters2: (function() {
return this.getEach('length2').reduce(function(prev, curr) {
return prev + curr;
})
}).property('@each.length2')
});
// child
App.WordController = Ember.ObjectController.extend({
lettersNo: (function() {
length = this.get('name').length;
// why only through 'set' the arrayController binds properly?
// if in parent controller I bind to '@each.length2', it works good. but why?
this.set('length2', length);
return this.get('name').length;
}).property('name')
});
handlebars:
<script type="text/x-handlebars" data-template-name="index">
<ul>
{{#each word in model itemController="word"}}
<li>{{input value=word.name}}</li> letters:
{{word.lettersNo}}
{{/each}}
</ul>
Total letters:{{numberOfAllLetters}} <br/> <!-- doesnt work -->
Total letters2:{{numberOfAllLetters2}} <br/> <!-- works -->
</script>
I am wondering if I am missing something and why i cannot use the same property in child's template, child's controller and binded to parent's controller.
Here is the fiddle: http://jsfiddle.net/licancabur/de1k7jcb/