English 中文(简体)
How to properly activate an MVC View in Sencha Touch V2
原标题:

I m running Sencha Touch V2 beta and I m looking at the most recent documentation.

I ve followed the Ext.application instructions and am trying to properly lay out my MVC application. Unfortunately I can t figure out how to actually load up a View with this approach.

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

Any help you might be able to offer would be greatly appreciated.

最佳回答

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:

Folder structure for Sencha Touch 2 application

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.

问题回答

Great answer by Abdel.

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





相关问题
Windows 7 multitouch capabilities with HTML5

I have a problem: There are HTML5/CSS3 mobile frameworks on the market like Sencha Touch and Phonegap which can use the multi-touch gestures of the iPad/iPhone, Android, etc. That s working fine, I ...

Getting started with Sencha Touch

I m an Ext veteran but have a few rather simple mobile apps i need to create and naturally i m looking at sencha touch. Ting is - most of the examples don t run up in Firefox/Opera. I m happily using ...

Custom icon in TabPanel fails

I m trying to add a custom icon to a TabPanel but when I do that it just shows a dark box with rounded corners. My css looks like this: http://pastebin.org/447682 The code in the url is base64 for ...

Sencha Touch and ExtJS

Sencha Touch looks impressive, and ExtJS looks nice. I am evaluating if I should use ExtJS or SproutCore for an upcoming app. Now that Sencha Touch is in the mix, I wonder if I choose ExtJS, it d be ...

Turning Sencha Touch-based app into a true native iPhone app?

As I understand, Sencha Touch is just a javascript library that lets you create websites that respond to multitouch and other features you find in native iPhone apps. So... Your end result is accessed ...

Is anyone using Sencha Touch for mobile development?

We re evaluating Sencha Touch for mobile development. Has anyone used this yet (I realize that it s still in beta), and if so, what are its strengths / weaknesses? How does it compare to alternatives? ...

热门标签