基于ExtJS项目实践: 用户界面与业务逻辑的解耦

下面将 用户界面称为UI  业务逻辑称为BL

 

几个重点

1. Ext.extend()

2. UI与BL解耦

 

每个模块分为3个文件

1. UI定义

2. BL和事件处理

3. 组织

 


 UI定义

 

// Account.ui.js 定义UI

 AccountUi = Ext.extend(Ext.form.FormPanel, {
    title: 'Account',
    labelWidth: 100,
    labelAlign: 'left',
    layout: 'form',
    width: 600,
    frame: true,
    initComponent: function() {
        this.items = [
            {
                xtype: 'container',
                autoEl: 'div',
                layout: 'column',
                items: [
                    {
                        xtype: 'container',
                        autoEl: 'div',
                        layout: 'form',
                        columnWidth: 0.5,
                        items: [
                            {
                                xtype: 'textfield',
                                fieldLabel: 'First Name',
                                anchor: '95%',
                                name: 'fname',
                                ref: '../../fname'
                            },
                            {
                                xtype: 'datefield',
                                fieldLabel: 'Birth of day',
                                anchor: '95%',
                                name: 'birthday',
                                ref: '../../birthday'
                            }
                        ]
                    },
                    {
                        xtype: 'container',
                        autoEl: 'div',
                        layout: 'form',
                        columnWidth: 0.5,
                        items: [
                            {
                                xtype: 'textfield',
                                fieldLabel: 'Last Name',
                                anchor: '95%',
                                name: 'lname',
                                ref: '../../lname'
                            },
                            {
                                xtype: 'combo',
                                fieldLabel: 'Sex',
                                anchor: '95%',
                                name: 'sex',
                                ref: '../../sex'
                            }
                        ]
                    }
                ]
            },
            {
                xtype: 'htmleditor',
                anchor: '98%',
                fieldLabel: 'Memo',
                height: 150,
                width: 300,
                name: 'memo',
                ref: 'memo'
            }
        ];
        this.fbar = {
            xtype: 'toolbar',
            items: [
                {
                    xtype: 'button',
                    text: 'Save',
                    ref: '../saveBtn'
                },
                {
                    xtype: 'button',
                    text: 'Reset',
                    ref: '../resetBtn'
                }
            ]
        };
        AccountUi.superclass.initComponent.call(this);
    }
});

 

BL和事件处理

 

// Account.js  处理业务逻辑和事件 关于如何引用到Form中的变量, 请参考 组件的 ref 的定义与配置

Account = Ext.extend(AccountUi, {
    initComponent: function() {
        Account.superclass.initComponent.call(this);
        
        this.saveBtn.on('click', this.doSaveAction, this);
    },
    doSaveAction:  function() {
        alert('do business A....');
        alert('do business B....');
    }
});

 

组织

 

// index.js

Ext.onReady(function() {

    var account = new Account({
        renderTo: Ext.getBody()
    });

    account.show();

});

 

如果为生成模块的UI感到苦恼,字段太多感到维护困难,那么ExtJS Designer将是选择之一。以后开发的工作量将从UI的排版和字段的维护降至最低点,而你所专注的只有业务逻辑的处理。

 

 

–end–

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值