Hybrid View

  1. #1
    Sencha User Surykat's Avatar
    Join Date
    Jul 2011
    Location
    BIALYSTOK, Poland
    Posts
    58
    Answers
    1
    Vote Rating
    1
    Surykat is on a distinguished road

      0  

    Default Unanswered: Basica view switching - how?

    Unanswered: Basica view switching - how?


    Hi!

    I'm new in MVC and I need some help in understand a logic of views and controllers. I have two questions.

    1) Can I have multiple controllers? For example, every view has own controller which is dynamically initialized when I switch view?

    2) What I am doing wrong with building a simple MVC app, when I setActiveItem to my second View when I click a button. And I want to go back to first view with another button. Everythings goes without errors, but when I come back to first view, all of handlers/listeners seems to be disactivated..

    Any help would be appreciated. My CODE:

    app.js:
    Code:
    Ext.Loader.setConfig({ enabled: true });
    
    
    Ext.application({
        name: 'MVC',
    
    
        controllers: ['Main']
    });
    view/main.js:
    Code:
    Ext.define('MVC.view.Main', {
        extend: 'Ext.Panel',
        alias: 'widget.main',
        
        initialize : function() {
            this.callParent();  
        },
        
        config: {
            fullscreen: true,
            items: {
                xtype: 'toolbar',
                docked: 'top',
                items: [{
                    xtype: 'button',
                    id: 'CLICK',
                    text: 'CLICK'
                }]
            }
        }
    });
    view/second.js:
    Code:
    Ext.define('MVC.view.Second', {
        extend: 'Ext.Panel',
        alias: 'widget.second',
        
        initialize : function() {
            this.callParent();  
        },
        
        config: {
            fullscreen: true,
            items: {
                xtype: 'toolbar',
                docked: 'top',
                items: [{
                    xtype: 'button',
                    id: 'KLIK2',
                    text: 'KLIK2'
                }]
            }
        }
    });
    controller/main.js:
    Code:
    Ext.define('MVC.controller.Main', {
        extend: 'Ext.app.Controller',
    
    
        config: {
            profile: Ext.os.deviceType.toLowerCase()
        },
    
    
        views : [
            'Main',
            'Second'
        ],
        
        refs: [{
            ref: 'main',
            selector: 'mainview',
            autoCreate: true,
            xtype: 'mainview'
        }, {
            ref: 'second',
            selector: 'secondview',
            xtype: 'secondview'
        }],
    
    
        init: function() {
            this.getMainView().create();
            
            this.control({
                '#CLICK': {
                    'tap': function() {
                        Ext.Viewport.setActiveItem({xtype:'second'});
                    }
                },
                
                '#CLICK2': {
                    'tap': function() {
                        Ext.Viewport.setActiveItem({xtype:'main'});
                    }
                }
            });
        }
    });

  2. #2
    Ext GWT Premium Member
    Join Date
    Apr 2009
    Location
    NYC
    Posts
    111
    Answers
    2
    Vote Rating
    1
    stan229 is on a distinguished road

      0  

    Default


    Have a look at this Q&A thread, it covers your same question:

    http://www.sencha.com/forum/showthre...ttons-with-MVC

  3. #3
    Sencha User Surykat's Avatar
    Join Date
    Jul 2011
    Location
    BIALYSTOK, Poland
    Posts
    58
    Answers
    1
    Vote Rating
    1
    Surykat is on a distinguished road

      0  

    Default


    I tried that solution and it didn't worked for me. That's the reason of the new thread which I have opened. Any other possible ideas?

  4. #4
    Sencha User
    Join Date
    Oct 2011
    Location
    Germany
    Posts
    146
    Answers
    4
    Vote Rating
    10
    Möhre will become famous soon enough

      0  

    Default


    I´ve got problems with view switching too.

    Sencha need´s to provide an example of a typical CRUD-App in MVC-style!
    Tabpanel with homepanel & listview, show editview on tap and switch back to listview after saving to localstore.

    This would make things much easier esp. for beginners!

Thread Participants: 2