sencha > MVC

3347 단어 sencha
app.js
Ext.application({
    name: 'Sencha',

    controllers: ['Main'],
    views: ['Main'],
    stores: ['Presidents'],
    models: ['President'],

    launch: function() {
        Ext.Viewport.add({	// 
            xtype: 'mainpanel'	//  views/Main  mainpanel 
        });
    }
});

 
view/Main.js
Ext.define('Sencha.view.Main', {// ,
    extend: 'Ext.navigation.View',// Ext  navigationView
    xtype: 'mainpanel',// mainpanel
    requires: [	// PresidentList  2 View;
        'Sencha.view.PresidentList'
    ],

    config: {
        items: [{
            xtype: 'presidentlist' // presidentlist  , view/PresidentList 
        }]
    }
});

 
view/PresidentList.js
Ext.define('Sencha.view.PresidentList', {
    extend: 'Ext.List',	// List Layout
    xtype: 'presidentlist',	//
    requires: ['Sencha.store.Presidents'],	//    store/Presdents  
    
    config: {
        title: 'American XX',	// List Layout  
        grouped: true,	//
        itemTpl: '{pic} ___ {name}',	//  
        store: 'Presidents',	//   Store   Presidents   
        onItemDisclosure: true	// 
    }
});

 
store/Presidents.js
Ext.define('Sencha.store.Presidents', {
    extend: 'Ext.data.Store', // 
    
    config: {
        model: 'Sencha.model.President', // model/President model,
        sorters: 'pic',	// XX 
        grouper : function(record) {	//record  model 
            return record.get('name')[0];	// xxx  
        },
        data: [
			{ pic: "a", name: "1" },
			{ pic: "b", name: "2" },
			{ pic: "c", name: "3" }
        ]
    }
});

 
model/President.js
Ext.define('Sencha.model.President', {
	//model    
    extend: 'Ext.data.Model',
    config: {
        fields: ['pic', 'name']// model this.data.xxx  
							   // model  store 
    },
	getFullName: function() {
		return this.get('pic') + '***' + this.get('name');	// pic name 
	}

});

 
controller/Main.js
Ext.define('Sencha.controller.Main', {
    extend: 'Ext.app.Controller',

    config: {
        refs: {
            main: 'mainpanel' // view
        },
        control: {
            'presidentlist': {//presidentlist  view  
				itemtap: 'showDetail'	// list  each Item  showDetail  
            }
        }
    },

    showDetail: function(list, idx, el, record) {// list 
        Ext.Msg.alert(record.getFullName());	// console.log
    }

});

 

좋은 웹페이지 즐겨찾기