2016最后一贴,终于调通一个测试示例,并发现一个BUG???

本文记录了作者使用ExtJS过程中遇到的问题及解决方案,特别是在创建用户表单界面时出现的bug,通过调整代码结构最终解决了编辑用户时无法正常工作的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

真的难点在于第一次调通。纠结五天,终于搞出界面。

也发现了一个书上代码,编辑用户时死活不通的情况,我将Links去了,改在data里,我X,,全OK了。。

原来的代码:

onAdd: function(button, e, options){
        this.createDialog(null);
    },

    onEdit: function(button, e, options){

        var me = this,
            records = me.getRecordsSelected();

        if(records[0]){
            me.createDialog(records[0]);
        }
    },

    createDialog: function(record){

        var me = this,
            view = me.getView();

        console.log(record);

        me.dialog = view.add({
            xtype: 'user-form',
            viewModel: {
                data: {
                    title: record ? 'Edit: ' + record.get('name') : 'Add User'
                },
                links: {
                    currentUser: record || Ext.create('Packt.model.security.User')
                }
            }
        });

        me.dialog.show();
    },

    getRecordsSelected: function(){
        var grid = this.lookupReference('usersGrid');
        return grid.getSelection();
    },

更改后的代码:

onAdd: function(button, e, options){
        this.createDialog(null);
    },
    createDialog: function(record){
        var me = this,
            view = me.getView(); //#1

        me.dialog = view.add({
            xtype: 'user-form', //#2
            viewModel: { //#3
                data: {
                    title: record ? 'Edit: ' + record.get('name') : 'Add User',
                    currentUser: record || { //#6
                        type: 'User', //#7
                        create: true
                    }//#4
                }
            }
        });

        me.dialog.show(); //#7
    },
    onEdit: function(button, e, options){
        var me = this,
            records = me.getRecordsSelected(); //#1
        if(records[0]){ //#2
            me.createDialog(records[0]); //#3
        }
    },
    getRecordsSelected: function(){
        var grid = this.lookupReference('usersGrid'); //#4
        return grid.getSelection(); //#5
    },

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值