jeudi 19 février 2015

Ember Singleton component, re use already rendered component.

I have an array in which items are added/removed dynamically. In handlebars template i have {{#each}} loop which iterates over this array and renders multiple components and views for for each item in the array.


A user action can remove an item from this array, when this happens ember destroys all the components/views corresponding to the deleted item. Which is fine.


Question : I have a component(a calendar) which i want to share among all the items in the array(each item in array renders a date field). But when an item is removed from array and calendar component was on date field of item being removed, the calendar component is also destroyed :(.


I have it working using a ContainerView with each date field to which i add the calendar component as a child view manually. Before removing an item from the array i check if that items data field had the calendar component as its child, if yes i remove the component from there and add it to a hidden ContainerView and then add it to whatever date field is clicked.


Is there something i am missing or doing wrong?


Is there a better way to do it?





Aucun commentaire:

Enregistrer un commentaire