I'm having a weird issue where a computed property isn't firing when it's dependent properties change.
Computed Property and Actions
answers: computed('variant.questionAnswers.[]', function() {
return get(this, 'variant.questionAnswers').sortBy('position');
}),
...
actions: {
reorderItems(answerModels) {
answerModels.forEach(function(item, index) {
set(item, 'position', index + 1);
});
}
}
The answerModels in the action is an array of all the answers, and setting the position works properly in that action. I can see the position changing in the ember inspector as well as when I inspect the individual models.
However, it does not update the view order because the answers computed property does not get fired.
I've tried changing the dependent property to variant.questionAnswers, variant.questionAnswers.@each.position, variant.questionAnswers.[], but nothing seem to fire when I change the position in the action.
How I got around it was add a timeHack attribute that makes it work, but obviously is not ideal...
timeHack: null,
answers: computed('timeHack', 'variant.questionAnswers.[]', function() {
return get(this, 'variant.questionAnswers').sortBy('position');
}),
actions: {
reorderItems(answerModels) {
answerModels.forEach(function(item, index) {
set(item, 'position', index + 1);
});
set(this, 'timeHack', new Date());
}
}
Any thoughts on how to get this to work?
Aucun commentaire:
Enregistrer un commentaire