我試圖過濾一個花費數據'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