1

I've tried the simple MVC example like this How to properly activate an MVC View in Sencha Touch V2 . It's ok, but let's say i want to add a button in the panel using a view.

I've tried to do following..

app.js :

Ext.Loader.setConfig({enabled: true});
Ext.application({
    name: 'rpc',
    appFolder: 'app',
    controllers: ['Home'],
    launch: function () {

        Ext.create('Ext.tab.Panel',{
            fullscreen: true,     
            tabBarPosition: 'bottom',
            items:[{
                title: 'Home',
                iconCls: 'home',
                html: '<img src="http://staging.sencha.com/img/sencha.png" />'
            },{
                title: 'Compose',
                iconCls: 'compose',
                xtype: 'mybutton'
            }]          
        });     
    }
});

control

    Ext.define('rpc.controller.Home', {
    extend: 'Ext.app.Controller',
    views: ['home.Button'],
    init: function() {    

        console.log('Home controller init method...');
    }
});

view

    Ext.define('rpc.view.home.Button', {
    extend: 'Ext.Panel',    
    alias: 'widget.mybutton',
    initialize: function() {
        this.items = [
            {
            xtype: 'button',
            cls  : 'demobtn',
            flex : 1
            }]
        ;

        this.callParent();  
    }
});

The result i receive is :

Uncaught TypeError: Cannot read property 'length' of undefined

Where is the error? What is the right way to add the button using a view with MVC in Sencha Touch 2.0 ?

Thanks.

Community
  • 1
  • 1

1 Answers1

1

Try changing the way you define your rpc.view.home.Button view, I don't call initialize() in my views, I just do:

Ext.define('rpc.view.home.Button', {
extend: 'Ext.Panel',
xtype: 'mybutton',
config: {
    items = [
        {
        xtype: 'button',
        cls  : 'demobtn',
        flex : 1
        }
    ]    
}
});
Roberto
  • 446
  • 5
  • 11