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

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

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

原来的代码:

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
    },

 

相关文章:

  • 2021-11-26
  • 2021-09-05
  • 2022-12-23
  • 2021-08-01
  • 2021-12-08
  • 2021-11-03
  • 2021-12-06
  • 2022-01-25
猜你喜欢
  • 2021-09-01
  • 2021-09-20
  • 2021-11-08
  • 2021-05-31
  • 2021-06-05
  • 2021-05-09
  • 2022-03-02
相关资源
相似解决方案