sencha-touch - 如何在 Sencha Touch V2 中正确激活 MVC View

标签 sencha-touch sencha-touch-2

我正在运行 Sencha Touch V2 beta,我正在查看最多 recent documentation .

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

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

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

最佳答案

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

Folder structure for Sencha Touch 2 application

在您的应用程序开发期间,您应该在您的 html 中使用 sencha-touch-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') 包含主页 View 的。

这是 Controller :

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

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

最后,我的主页 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();  
    }       
});

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

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

关于sencha-touch - 如何在 Sencha Touch V2 中正确激活 MVC View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7815905/

相关文章:

extjs - 在自定义组件中动态加载数据

android - Sencha Touch 2 - 旋转木马仅在构建后卡在第一个面板上

javascript - 在推送 View 上隐藏按钮并在返回 ListView 时显示它

javascript - Sencha Touch 2 的大型离线存储

java - 使用 Jackson 进行反序列化 : "org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of [projectname]."

html - 在面板上绘制 Html 表格?

javascript - 在初始化函数中定义对象的项

javascript - 在选择合适的 iOS Mobile Safari Web 开发工具(jQuery Mobile/Sencha Touch/等)时感到沮丧

javascript - 将基于 Sencha Touch 的应用程序源代码转换为 native Objective-C 代码

javascript - Sencha Touch 和 Cookie