【问题标题】:How to properly activate an MVC View in Sencha Touch V2如何在 Sencha Touch V2 中正确激活 MVC 视图
【发布时间】:2011-10-19 02:26:23
【问题描述】:

我正在运行 Sencha Touch V2 测试版,我看的最多的是recent documentation

我已按照Ext.application 的说明进行操作,并正在尝试正确布置我的 MVC 应用程序。不幸的是,我无法弄清楚如何使用这种方法实际加载视图。

index.js

Ext.application({

    name: 'rpc',
    defaultUrl: 'home/index',
    controllers: ['home'], //note: define controllers here
    launch: function () {

        console.log('Ext.application ~ launch'),

        Ext.create('Ext.TabPanel', {
            id: 'rpc-rootPanel',
            fullscreen: true,
            tabBarPosition: 'bottom',
            items: [{
                title: 'Home',
                iconCls: 'home'
            }]
        });

        Ext.create('Ext.viewport.Viewport', {
            id:'rpc-rootPanel',
            fullscreen: true,
            layout: 'card',
            cardSwitchAnimation: 'slide'
        });

    }
});

homeController.js

Ext.define('rpc.controller.home', {
    extend: 'Ext.app.Controller',
    views: ['home.index'],
    stores: [],
    refs: [],
    init: function () {
        console.log('rpc.controller.home ~ init');
    },

    index: function () {
        console.log('rpc.controller.home ~ index');
    }
});

indexView.js

Ext.define('rpc.view.home.index', {
    extend: 'Ext.Panel',
    id: 'rpc-view-home-index',
    config: {
        fullscreen: true,
        layout: 'vbox',
        items: [{
            xtype: 'button',
            text: 'Videos',
            handler: function () {
            }
        }],
        html:'test'
    }
});

如果您能提供任何帮助,我们将不胜感激。

【问题讨论】:

    标签: sencha-touch sencha-touch-2


    【解决方案1】:

    新版本遵循 ExtJS 4 中引入的 MVC 概念。您应该阅读Architecture guide,因为 Sencha Touch 将遵循相同的架构。这是我的文件夹结构:

    在开发应用程序期间,您应该在 html 中使用 sencha-touch-all-debug-w-cmets.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: 'homepage'
                }]          
            });     
        }
    });
    

    注意,我是如何使用别名 (xtype: 'homepage') 包含主页视图的。

    这里是控制器:

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

    最后,我的主页视图:

    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();  
        }       
    });
    

    别名属性用于在需要时实例化类的实例。您也可以使用 Ext.create 方法。

    我希望这将帮助您开始使用 Sencha Touch。

    【讨论】:

    【解决方案2】:

    Abdel 的回答很好。

    您也可以通过配置文件执行此操作,如以下答案所示: Sencha Touch 2.0 MVC tutorial

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多