如何在Sencha Touch V2中正确激活MVC视图 [英] How to properly activate an MVC View in Sencha Touch V2

查看:13
本文介绍了如何在Sencha Touch V2中正确激活MVC视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行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'
        });

    }
});

home Controller.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'
    }
});

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

推荐答案

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

在开发应用程序期间,您应该在html中使用sencha-ouch-all-debug-w-Comments.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();  
    }       
});

alias属性用于在需要时实例化类的实例。您还可以使用Ext.Create方法。

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

这篇关于如何在Sencha Touch V2中正确激活MVC视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆