Results 1 to 3 of 3

Thread: Specifying config values (listeners) when using xtype. (Beginner level question)

  1. #1
    Roberto Lopez's Avatar
    Join Date
    Feb 2016
    Location
    Dallas Texas USA
    Posts
    23
    Answers
    3
    Vote Rating
    0
      0  

    Default Specifying config values (listeners) when using xtype. (Beginner level question)

    Code:
    Ext.application({
        name: 'MyApp',
    
        requires: ['MyButtonController'],
    
        launch: function () {
            var vp = new Ext.container.Viewport({
                items: [{
                    xtype: 'button',
                    controller: 'mybutton-controller',  //<=== Is not working (No method name 'onButtonClick')
                    text: 'Click',
                    listeners: { 
                        click: 'onButtonClick'
                    }
                }]
            });
        }
    });
    
    Ext.define('MyButtonController', {
        extend: 'Ext.app.ViewController',
        alias: 'controller.button-controller',
        
        onButtonClick: function() {
            Ext.Msg.alert('Status', 'Button was clicked.');
        }
    });
    

  2. #2
    Sencha User
    Join Date
    Feb 2017
    Posts
    15
    Answers
    3
    Vote Rating
    2
      1  

    Default

    https://fiddle.sencha.com/#view/editor&fiddle/2lrr


    Code:
    Ext.define('ButtonController', {
        extend: 'Ext.app.ViewController',
        alias: 'controller.buttoncontroller',
    
    
        onButtonClick: function () {
            Ext.Msg.alert('Status', 'Button was clicked.');
        }
    });
    
    
    Ext.application({
        name: 'MyApp',
    
    
        requires: ['ButtonController'],
    
    
        launch: function () {
            var vp = new Ext.container.Viewport({
                controller: 'buttoncontroller', //<--------------------------placed it in a parent component
                items: [{
                    xtype: 'button',
    
    
                    text: 'Click',
                    handler: 'onButtonClick'
                }]
            });
        }
    });

  3. #3
    Roberto Lopez's Avatar
    Join Date
    Feb 2016
    Location
    Dallas Texas USA
    Posts
    23
    Answers
    3
    Vote Rating
    0
      0  

    Default

    Thank you for your replay.

    I found a very helpful explanation here.

    For listeners declared on an instance config, the component itself is skipped and the framework searches upward starting with the parent container.

Similar Threads

  1. Replies: 5
    Last Post: 28 Dec 2015, 6:11 AM
  2. Why ViewController method binding not working?
    By IvanJ in forum Ext JS 6.x Q&A
    Replies: 5
    Last Post: 12 Oct 2015, 12:30 PM
  3. Replies: 2
    Last Post: 2 Oct 2014, 8:37 AM
  4. Replies: 1
    Last Post: 11 Aug 2014, 5:17 AM
  5. Replies: 1
    Last Post: 10 Jun 2014, 6:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •