-
6 Dec 2012 12:53 AM #1
Unanswered: Load and unload active view into viewport
Unanswered: Load and unload active view into viewport
Hi,
I'm using ST2.1 MVC.
I have a login view which on success loads a view with a list (dataview) of items.
The user can click an item and it loads an individual edit view for that item. E.g. each item is a different type and has a different type of edit view.
e.g
Login -> Items -> Item Edits.
I found some discussion about how views should be destroyed? from the viewport but I could not find a definitive approach or discussion in the docs about how to go about this.
With some experimentation in my login button success I do the following to show the 'items' view:
In the MyApp.view.Items I have a logout button which does thisCode:var itemsview= Ext.create('MyApp.view.Items'); Ext.Viewport.add(itemsview); // I dont destroy the login screen as I have a logout button that when pressed removes it (see next code section) Ext.Viewport.setActiveItem(itemsview);
which mostly works to (seemingly) remove the MyApp.View.Items from the viewport and the login screen is displayed.Code:Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);
From the clicking on an item in MyApp.View.Items view I call the Edit view (associated with the item ) in a similar way ( from a tap event ):
This loads the edit view (although I have to reload some shared components that where already in the item view - not sure why - will create a separate post for this).Code:var editview= Ext.create('MyApp.view.Edit'); Ext.Viewport.add(editview); // not destroying the itemview as we want to come back to that from the editview Ext.Viewport.setActiveItem(editview);
Now I would have thought that if I have a 'back' button on my edit view and do the following (below) that this would take me back to the 'items' list view - it doesnt it takes me back to the 'login' screen!
Obviously I am missing something here in my understanding.
Code:// remove the active view from the viewport - which is the edit scren // this will show the list screen as we never removed that i.e. that // is the previous one in the stack. Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);
Any help / understanding of best approach to moving views in and out of the app viewport to ensure memory management and screens don't need to be repopulated with data with this and in my example above how to achieve this would be appreciated greatly.
thx
-
8 Dec 2012 5:47 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,624
- Vote Rating
- 434
- Answers
- 3105
If you do:
And the active item was the list view, that list view will be destroyed so to go back to the list view you would have to create a new instance of that list view.Code:Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
9 Dec 2012 5:18 PM #3
thanks,
not sure why but I had to replace..
withCode:Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true)
for this to work.Code:Ext.Viewport.setActiveItem(this.getRefToMyScreen());
-
9 Dec 2012 6:14 PM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,624
- Vote Rating
- 434
- Answers
- 3105
remove() will only remove the item. setActiveItem makes a new item active but does not remove the old item.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
9 Dec 2012 6:41 PM #5
thanks
so is the best practice to always remove and re-add for memory etc. management?


Reply With Quote