extjs4.1 mvc

结合ext4.1的英文文档和Extjs4.0学习指南(中文)

目录结构:
项目下放: index.html, app.js, ext-4.1, ext-4.07, page1, app。
app下放 controller, model, store, view。
controller下放Users.js, view下放 user/List.js

==index.html==
<html>
<head>
    <title>Hello Ext</title>
    <link rel="stylesheet" type="text/css" href="ext-4.1/resources/css/ext-all.css">
    <script type="text/javascript" src="ext-4.1/ext-all-debug.js"></script>
    <script type="text/javascript" src="app.js"></script>
</head>
<body>
</body>
</html>

==app.js==
Ext.Loader.setConfig({enabled: true}); 
Ext.application({
    name: 'AM',
    
    appFolder: 'app',
    
    controllers: [
        'Users'
    ],
    
    launch: function(){
        Ext.create('Ext.container.Viewport', {
            layout:'fit',
            //一个对象的话直接用{} ,多个用[{}, {}...]
            items:{
                xtype:'myuserlist'
            }
        });
    }
    
});

==Users.js==
Ext.define('AM.controller.Users', {
    extend:'Ext.app.Controller',
   
    views: [
        'user.List'
    ],
    
    init:function(){
        //这个类集成自Controller, controll函数是Controller的成员函数
        this.control({
            //css选择器
            'viewport>panel':{
                //给页面中选择到的元素对象添加渲染时事件处理
                render: this.onPanelRendered
            }
        });
    },
    
    //自定义当前类的成员函数
    onPanelRendered: function() {
        console.log('The panel was rendered ddd');
        alert('the panel literally was rendered.');
    }
});

==List.js==
Ext.define('AM.view.user.List', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.myuserlist',
    title: 'All Users',
    
    initComponent: function() {
        this.store = {
            fields: ['name', 'email'],
            data: [
                {name: 'Lampard', email:'[email protected]'},
                {name: 'Drogba', email:'[email protected]'},
                {name: 'Terry', email:'[email protected]'}
            ]
        };
        
        this.columns = [
            {header:'Name', dataIndex:'name', flex:1},
            {header:'Email', dataIndex:'email', flex:1}
        ];
        
        this.callParent(arguments);
    }
});

你可能感兴趣的:(extjs4)