jeudi 29 janvier 2015

View not recognizing id change after action is triggered

In my app, I have a model called projects, and another called users. In the user model, it has an array that contains the ids of certain projects. I have a component that, when clicked, calls an action within a controller. That action simply adds or removes a project id from that array in the user's model. However, if I click on the component, then switch to another project's show page, Ember doesn't recognize that the project's id changed. It recognizes the rest of the project's properties, except for its id. Any idea why this may be the case?


In the component:



click: function() {
this.toggleProperty('isFavorite');
this.sendAction('action', this.get('projectId'), this.get('isFavorite'));
}


The action in the controller:



updateFavorites: function(id, isSelected) {
var user = this.get('currentUser');

user.then(function(user) {
var favorites = user.get('favorites');

if (isSelected) {
favorites.pushObject(id);
} else {
favorites.removeObject(id);
}
user.set('favorites', favorites);

user.save();
});
}


Note that it switches views normally if the user simply switches from one project show page to another. It's only when they click on the component that it stops working properly.


Any ideas? Thoughts?





Aucun commentaire:

Enregistrer un commentaire