How to properly activate an MVC View in Sencha Touch V2

我只是一个虾纸丫 提交于 2019-12-04 13:41:07

The new release follows MVC concepts introduced in ExtJS 4. You should read Architecture guide because Sencha Touch will be following the same arch.Here is my folder structure:

During development of your application, you should make use of sencha-touch-all-debug-w-comments.js in your html. This helps in debugging your application.

Here is the application class:

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: 'homepage'
            }]          
        });     
    }
});

Note, how I have included the homepage view using the alias (xtype: 'homepage').

Here is the controller:

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

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

And finally, my Homepage view:

Ext.define('rpc.view.home.HomePage', {
    extend: 'Ext.Panel',    
    alias: 'widget.homepage',
    config: {               
        html: '<img src="http://staging.sencha.com/img/sencha.png" />'
    },
    initialize: function() {
        console.log("InitComponent for homepage");      
        this.callParent();  
    }       
});

The alias property is used to instantiate instance of the class when needed. You could also use the Ext.create method.

I hope this will help you get started with Sencha Touch.

Grgur

Great answer by Abdel.

You can also do it though profiles, as demonstrated in this answer: Sencha Touch 2.0 MVC tutorial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!