1. #1
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    84
    Answers
    4
    Vote Rating
    1
    busaware1 is on a distinguished road

      0  

    Default 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:

    Code:
    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);
    In the MyApp.view.Items I have a logout button which does this

    Code:
    Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);
    which mostly works to (seemingly) remove the MyApp.View.Items from the viewport and the login screen is displayed.

    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 ):

    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);
    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).

    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

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,620
    Answers
    3452
    Vote Rating
    817
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    If you do:

    Code:
    Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);
    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.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    84
    Answers
    4
    Vote Rating
    1
    busaware1 is on a distinguished road

      0  

    Default


    thanks,

    not sure why but I had to replace..
    Code:
    Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true)
    with
    Code:
    Ext.Viewport.setActiveItem(this.getRefToMyScreen());
    for this to work.

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,620
    Answers
    3452
    Vote Rating
    817
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    84
    Answers
    4
    Vote Rating
    1
    busaware1 is on a distinguished road

      0  

    Default


    thanks
    so is the best practice to always remove and re-add for memory etc. management?

Thread Participants: 1

Tags for this Thread