随笔 - 118  文章 - 0 评论 - 341 阅读 - 299万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

接上面的船舶管理业务,这里介绍添加和修改操作。

目录

1. 添加操作

2. 修改操作

3. 在线演示

 

1. 添加操作

1.1 创建AddShipWindow.js

在业务中的view目录下创建一个AddShipWindow.js文件,表示一个增加船舶的窗口组件。

此文件中包含了一个form组件用于显示所要添加的字段:船舶名称、状态、吨数和核载人数。

具体代码如下

 

1.2 入口设置

在上一篇的grid工具栏中加入【添加】按钮:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Ext.create('Ext.Action', {
    icon: 'Resources/icon/add.png',
    text: '添加',
    name: 'AddBtn',
    handler: function (thisControl, event) {
        var winConfig = {
            title: '添加船舶',
            oprType: 'add',
            url: 'Business/ShipMgr/Add',
            successCallback: function () {
                shipMgrStore.loadPage(1); // 添加成功后刷新Store
            }
        };
        var win = Ext.create('App.ShipMgr.view.AddShipWindow', winConfig);
        Ext.getCmp('app_tabContainer').activeTab.add(win);
        win.show();
    }
})

 

1.3 运行图

 

2. 修改操作

2.1 修改窗口

船舶业务的修改窗口可以跟添加窗口公用一个,需要在弹出窗口时判断为添加操作还是别的操作。

若非添加操作,如:查看、修改时,加载本次请求的船舶信息并填充到具体的form表单里。

在AddShipWindow.js文件里添加如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 渲染结束后
me.on('afterrender', function () {
    // 1.非添加操作,查询具体的船舶
    if (_oprType != 'add') {
        me.setLoading(true);
        Ext.Ajax.request({
            method: 'POST',
            type: 'ajax',
            url: 'Business/ShipMgr/QueryById',
            params: {
                shipId: _shipId
            },
            success: function (response) {
                var rs = Ext.JSON.decode(response.responseText);
                if (rs.success == false) { //操作失败
                    Ext.Msg.alert('系统提示', rs.msg);
                }
                else {
                    var en = Ext.create('App.ShipMgr.model.ShipModel', rs.data);
                     // 填充数据
                     shipForm.loadRecord(en);
                }
                me.setLoading(false);
            },
            failure: function (response, opts) {
                me.setLoading(false);
                Ext.Msg.alert('系统提示', '操作失败');
            }
        });
    }
});

  

2.2 入口设置

【修改】按钮比较特殊,在默认情况是隐藏状态,只有选中了grid组件中的一条记录才显示出来。

2.2.1 创建按钮

在上一篇的grid工具栏中加入【修改】按钮:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Ext.create('Ext.Action', {
    icon: 'Resources/icon/edit.png',
    text: '修改',
    name: 'EditBtn',
    hidden:true,
    handler: function (thisControl, event) {
        var winConfig = {
            title: '修改船舶',
            oprType: 'edit',
            url: 'Business/ShipMgr/Update',
            shipId:selectData.ShipId,
            successCallback: function () {
                shipMgrStore.reload(); // 修改成功后刷新Store
            }
        };
        var win = Ext.create('App.ShipMgr.view.AddShipWindow', winConfig);
        Ext.getCmp('app_tabContainer').activeTab.add(win);
        win.show();
    }
})

 

2.2.2 隐藏按钮

每次shipMgrStore发起请求时都要隐藏【修改】按钮:

1
2
3
4
5
6
7
8
9
var shipMgrStore = Ext.create('Ext.data.Store', {
    // ...
    listeners: {
        beforeload: function (thisStore, record, opts) {
            thisStore.proxy.extraParams = searchConditionObj; // 附加检索条件
            shipMgrToolBarPanel.down('[name=EditBtn]').hide(); // 隐藏【修改】按钮
        }
    }
});

 

2.2.3 显示按钮

选中shipMgrGrid的某条数据时显示按钮:

1
2
3
4
5
6
7
8
9
var shipMgrGrid = Ext.create('Ext.grid.Panel', {
    // ...
    listeners: {
        cellclick: function (thisGridView, td, cellIndex, record, tr, rowIndex, e, eOpts) {
            selectData = record.data; // 获取选中的数据
            shipMgrToolBarPanel.down('[name=EditBtn]').show(); // 显示【修改】按钮
        }
    }
});

 

2.3 运行图

 

3. 在线演示

在线演示http://www.akmsg.com/ExtJS/index.html#App.ShipMgr.ShipMgrTab

 

posted on   FangMu  阅读(4209)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示