基础模型更改时,组件不会重新呈现

时间:2013-12-06 17:43:23

标签: ember.js ember-data

我有一个按层次顺序排列的模型数据。我使用组件来渲染模型数据,使用另一个组件将数据添加到模型中。我遇到的问题是,当我在根级别添加模型数据时,它会正确呈现,但是当我尝试将模型数据添加到一个深度时,视图不会更新。

这是一个演示我的问题的简单示例:http://jsbin.com/UhIdoxOR/1/

因此,如果我在根级别问题之后添加问题,则视图会更新。但是,如果我尝试在子级别添加问题,则视图不会更新。 当模型更改时,我该怎么做才能使适当的组件重新渲染?

谢谢, DEE

1 个答案:

答案 0 :(得分:1)

在您的QuestionController中,hasChildrenchildQuestions计算属性与property('questions')一致,但这不正确,因为hasChildren取决于childQuestions.length由于过滤器而导致childQuestion questions.@each.parentQuestionId。所以你需要更新到以下内容:

    App.QuestionController = Ember.ObjectController.extend({
        needs: 'questions',
        questions: Ember.computed.alias("controllers.questions"),

        hasChildren: function () {
            return (this.get('childQuestions.length') > 0);
        }.property('childQuestions.length'),

        childQuestions: function () {
            return (this.get('questions').filterBy('parentQuestionId', parseInt(this.get('id'))));
        }.property('questions.@each.parentQuestionId')
    });

这是您更新的jsbin http://jsbin.com/UhIdoxOR/3/edit

相关问题