Quantcast
Viewing all articles
Browse latest Browse all 4827

Is there an 'array pointer' in model loop or set() function behaves like computed?

@kimek wrote:

Hello there I’ve spend now 10h on this and still couldn’t figured out what’s going on.

I have 2 components:

{{task-component task=visitor.task}}

{{answer-component task=visitor.task}}

Relationship for models:

Visitor: task: DS.hasMany(‘task’, {inverse: ‘visitor’})

Task: visitor: DS.belongsTo(‘visitor’,{inverse:‘task’})

Everything works fine however when I’m using in task-component:

didReceiveAttrs() {
        let defaultAnswers = this.get('questions.answers'); // question is service, answer is property only used here
        this.get('task').forEach(function(item) {
            item.set('answers',defaultAnswers); // <- this is the issue
        });
    },

It’s binding defaultAnswers to answer attribute for all of task data (visitor have oneToMany relation).

After going to ‘answer-component’ -> answer-item ( which is in handelbars loop for task) -> filling form -> set(‘task.answer’,answer) -> all of task.answer are updated.

Any idea why this happens ?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4827

Trending Articles