我试图过滤一个花费数据'hasMany'字段的内容。我的模型具有一定的子问题,我想用Ember.js计算属性过滤器hasMany数组
{{#each childOptions}}stuff{{/each}}
当我把这个我控制器上渗入到我的控制器和显示在模板上的属性“childOptions”,它的工作原理,并在适当的值的每个迭代:
childOptions: Ember.computed.filterBy('model.subquestions', 'surveyQuestionType.name', 'childOption'),
但是,当我这样做,什么都没有显示。
childOptions: Ember.computed.filter('model.subquestions', function(subquestion) {
return subquestion.get('surveyQuestionType.name') === 'childOption';
}),
“surveyQuestionType”是在型号为“子问题”存在DS.belongsTo,它有一个“名称”属性。
我想了解为什么'filterBy'方法有效,而'filter'方法没有(为了将来可以使用'filter'来处理更复杂的查询)。我认为它与Promise和我在filter函数中使用的语法subquestion.get('property')
有关。
编辑:
这是模型:
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')''undefined',我很确定是这个问题,但我不知道如何解决它!如果我在模板中做了一个简单的'{{#each subquestions}} {{surveyQuestionType.name}} {{/ each}}',我可以看到该属性就好了。 – leejt489 2014-10-08 22:45:13