1. #1
    Sencha User
    Join Date
    Sep 2010
    Location
    India
    Posts
    40
    Answers
    2
    Vote Rating
    0
    pratik016 is on a distinguished road

      0  

    Default Answered: Avoid multiple instance of view in MVC

    Answered: Avoid multiple instance of view in MVC


    Hello,

    I am facing the problem at MVC architecture. I might be doing something wrong but cannot identify the actual problem.

    I am using Ext.create for getting views. But it creates new instance each time when clicking button. So my event will call multiple times. When creating first time view, event calls one time. second time creating same views event call two times.. and it is increasing on each button click event.

    Here is my code. please let me know if I am doing anything wrong here...

    Code:
    /*controller from I am getting other controller's view*/
    Ext.define('Test.controller.Landing', {
        extend: 'Ext.app.Controller',    
        views: ['Landing'],
    
    
        init: function (application) {        
    
    
            var me = this;
            this.control(
            {
             
               'landing button[action="test"]': {
                    click: function (t, e, eo) {//t => this, e => event, eo => Eoptional
                        var c = me.getController('Newpage');
                        c.init();
                        var instanceWidget = Ext.widget('newpage');
                        var ws = Ext.getCmp('right_region');
    
    
                        ws.removeAll();
                        ws.add(instanceWidget);
                        ws.doLayout();
                        
                    }
                }
            }); 
            this.callParent();
        }
    });
    Code:
    /*Controller and view that are creating multiple events*/
    Ext.define('Test.controller.Newpage', {
        extend: 'Ext.app.Controller',    
        views: ['Newpage'],
    
    
        init: function (application) {       
        
            //Ext.create('widget.landing'); 
            this.control(
            {
              'newpage': {    
                 afterrender: function (t, eOpt) {
                    alert('New page');
                }
              },
              
               'newpage button[action="testc"]': {
                    click: function (t, e, eo) {//t => this, e => event, eo => Eoptional
                        /*These events call multiple times*/
                        alert('newpage button');
                    }
                }
            }); 
            this.callParent();
        }
    });
    Also I am attaching file for my small code here.
    Attached Files

  2. Looking at the fact that you are calling the init() of a controller yourselfs I believe that this is the issue here to. Do not call init() yourself, every time init() is executed, your control() call is executed and the new instance starts listening to the events parallel to the already existing instances Of course, they all handle the event after each other, which makes it look like the event is being fired more then once.

    In a nutshell: Don't call int() on a controller, the framework takes care of it if you use Ext.app.Controller.getController()

  3. #2
    Sencha User
    Join Date
    Sep 2010
    Location
    India
    Posts
    40
    Answers
    2
    Vote Rating
    0
    pratik016 is on a distinguished road

      0  

    Default


    Anyone knew this MVC issue?
    please let me know. if not getting question then also. I really need the solution for this.

  4. #3
    Sencha User
    Join Date
    Dec 2009
    Location
    Enschede, The Netherlands
    Posts
    327
    Answers
    16
    Vote Rating
    13
    flanders will become famous soon enough

      1  

    Default


    Looking at the fact that you are calling the init() of a controller yourselfs I believe that this is the issue here to. Do not call init() yourself, every time init() is executed, your control() call is executed and the new instance starts listening to the events parallel to the already existing instances Of course, they all handle the event after each other, which makes it look like the event is being fired more then once.

    In a nutshell: Don't call int() on a controller, the framework takes care of it if you use Ext.app.Controller.getController()
    Last edited by flanders; 7 Dec 2012 at 11:39 AM. Reason: removed unnecessary lecture / added sensible details

  5. #4
    Sencha User
    Join Date
    Sep 2010
    Location
    India
    Posts
    40
    Answers
    2
    Vote Rating
    0
    pratik016 is on a distinguished road

      0  

    Default


    Thanks for replying.. in MVC we have to call init function at one time only.
    It works now.. thank you for your help.

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi