Reputation: 195
I have a page where the model is initially loading, but on subsequent link-to's to the same route, it's not updating correctly. I'm using the Ember data store.
For the sake of example, my page is a list of foods. I have a navigation with fruits, vegetables, meats, etc. A user clicks on this and a link-to sends them to foods.food route.
The model is
model(params) {
return RSVP.hash({
foodName: params.foodName,
foodItems: this.store.findAll('food-items', {adapterOptions: {foodName: params.foodName}} )
});
}
In my afterModel( food, transition )
food.foodItemsArr = food.foodItems.filter((foodKey) => {
return (foodKey.get('foodName') === food.foodName);
});
Then in my hbs template
{{#each model.foodItemsArr as |key|}}
...
{{/each}}
When a user initially clicks (fruit) on the list of food types, it loads up fruits as it should. When they then click on a different type (vegetable) after that, the food.foodItemsArr is giving a length of 0. Then if they click to a third food (meat) and then back to vegetable, the vegetables show up. It's almost as if the data store isnt getting updated fast enough by the model before afterModel fires. I've checked and the data is being filtered and returned properly by the server on each call. Help!
Upvotes: 0
Views: 436
Reputation: 195
Credit to @torazaburo for pointing me in the right direction.
I needed to add { reload: true }
to
foodItems:
this.store.findAll('food-items', {adapterOptions: {foodName: params.foodName}, reload: true} )
to force the model to reload.
Upvotes: 3