I am trying to filter the contents of a ember-data 'hasMany' field. My model has some subquestions, which I want to filter into a property 'childOptions' on my controller and display in the template using
{{#each childOptions}}stuff{{/each}}
When I put this on my controller, it works and the each iterates over appropriate values:
childOptions: Ember.computed.filterBy('model.subquestions', 'surveyQuestionType.name', 'childOption'),
However when I do this, nothing is shown.
childOptions: Ember.computed.filter('model.subquestions', function(subquestion) {
return subquestion.get('surveyQuestionType.name') === 'childOption';
}),
'surveyQuestionType' is a DS.belongsTo that exists on the model for 'subquestions', and it has a 'name' property.
I want to understand why the 'filterBy' method works, while the 'filter' method does not (so that I can use 'filter' for more complex queries in the future). I think it has something to do with promises, and the subquestion.get('property')
syntax that I am using inside the filter function.
EDIT:
This is the model:
App.SurveyQuestion = DS.Model.extend(Ember.Validations.Mixin, {
surveyQuestionType: DS.belongsTo('surveyQuestionType', { async: true }),
display: DS.belongsTo('surveyQuestionDisplay', { async: true, inverse: 'surveyQuestion' }),
sortOrder: DS.attr('number'),
parent: DS.belongsTo('surveyQuestion', { async: true, inverse: 'subquestions' }),
parentDependencyCriteria: DS.attr('string'),
required: DS.attr('boolean'),
surveySections: DS.hasMany('surveySectionQuestion', { async: true, inverse: 'surveyQuestion' }),
subquestions: DS.hasMany('surveyQuestion', { async: true, inverse: 'parent' })
});
subquestion.get('surveyQuestionType.name')
returnsundefined
, which I am pretty sure is the problem, but I don't know how to fix it! If I do a simple{{#each subquestions}}{{surveyQuestionType.name}}{{/each}}
in my template I can see the property just fine. – leejt489