Sencha touch: best way to set values for elements every time the view is shown?

194 Views Asked by At

In my sencha touch 2.3 app, I have a page that has few toggle fields, text fields etc. I want to set values on these fields every time the page is shown (it might have different set of values every time).

The parent container of this page is a panel that has card layout. I show the different pages using setActiveItem('pagextype');

Now, if I set values during initialize, it will get set once, but the next time the page is shown, initialize will not be called. And the elements will not be set to the new values.

Instead of initialize, I used painted event. This works fine. But whenever I go to the page, for a moment it displays the old values and then updates itself to the new values.

What is the best way to handle this scenario?

1

There are 1 best solutions below

0
On

You can follow below steps.

  1. Store data in some array or any object(let say OBJ) during initialize().
  2. Create a method updateData(index),which is responsible for updating data in the card layout element on the basis of index.this method is called from activeItemChange event function,which is called whenever there we swipe the item in card.
  3. Now by default index 0 item on card layout is shown.
  4. when we swipe,activeItemChange for the next item is called,you can write your logic inside updateData() method to update the data from the initial array/object(OBJ) on the basis of index.