繁体   English   中英

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

[英]component not re-rendering when underlying model changes

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

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

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

谢谢迪

在您的QuestionController ,具有具有property('questions')hasChildrenchildQuestions计算属性,但这是不正确的,因为由于过滤器的原因, hasChildren取决于问题的childQuestions.lengthchildQuestion 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM