1

I'm developping an Extjs app. Here is one of my controllers

Ext.define('ACP.controller.CodeTabs', {
extend: 'Ext.app.Controller',

/*
views: [
    'CodeTabs'
],
*/

refs: [
    {
        ref: 'codetabs',
        selector: 'codetabs',
    }
],

init: function() {
    this.application.on({
        addtab: this.addTab,
        closetab: this.closeTab,
    });
},

addTab: function() {
    var tabs = this.getCodetabs();
    tabs.add(
        {
            title: 'New tab',
            iconCls: 'tabs',
            html: 'VICTORY',
        }
    ).show();
},

closeTab: function() {
    alert("closetab");
},
});

An here is the related view:

Ext.define('ACP.view.CodeTabs', {
extend: 'Ext.tab.Panel',
alias: 'widget.codetabs',
layout: 'fit',
items: [
    {
        title: 'Test',
        html: 'HELLO ASLAN'
    }
],
});

The problem is that the getter this.getCodetabs() is undefined. Isn't it supposed to be autogenerated by refs ? What am I doing wrong ?

Here is my application : http://atomcodepad.com/acp You can try to click on the "addtab" button to see my problem happening.

fwoelffel
  • 412
  • 7
  • 16

1 Answers1

2

You're in the scope of the Application, not the Controller where the ref is defined. Use the getController(name) method to get a reference to the controller, from there your getter is defined.

chinabuffet
  • 5,278
  • 9
  • 40
  • 64
  • I corrected it like that: ... addTab: function() { var tabs = this.getController('CodeTabs').getCodetabs(); tabs.add( { title: 'New tab', iconCls: 'tabs', html: 'VICTORY', } ).show(); }, ... Is that the right way to do ? In the Extjs doc I didn't see a single reference to the controller before calling the getter. Whatever, now it works, thank you very much ! – fwoelffel Sep 27 '12 at 13:36