I am trying to access an object within an array inside handlebars, on Ember.js. I've tried the following combinations:
1 {{render "input-validation-message" validity.options.[_view.contentIndex]}}
2 {{render "input-validation-message" validity.options._view.contentIndex}}
3 {{render "input-validation-message" validity.options[_view.contentIndex]}}
The array is validity.options and the index is _view.contentIndex, which is the only way I know how to access the index within {{#each}} loops on Ember.js.
None of the three methods are passing the object through. Does anyone have a solution?
EDIT:
After some playing around, I found out that the _view.contentIndex is not being accessed inside of an {{unless}} or {{if}} block. My code looks a little like this:
{{#each modelArray}}
{{#unless _view.contentIndex}}
[code here that needs to access _view.contentIndex]
{{else}}
[more code here that needs to access _view.contentIndex]
{{/unless}}
{{/each}}
Is there a way to get pass this issue?
FIXED!
I modified the correct answer below slightly:
{{#each item in modelArray itemController='foo'}}
{{render "input-validation-message" item.validityOption}}
{{/each}}
App.FooController = Ember.ObjectController.extend({
validityOption: function(){
var model = this.get('model'),
eachController = this.get('target'),
parentController = eachController.get('target'),
idx = eachController.get('content').indexOf(model);
return parentController.get('validity.options').objectAt(idx);
}.property('model')
});
If the array is not an Ember.Array, use [] not objectAt().