如何覆盖 EXTJS 中的模型并添加额外的字段?

How to override model in EXTJS and add extra field?

如何在 EXTJS 中覆盖模型? 例如,如果我将模型定义为:

Ext.define('Mypp.model.Class1', {
    extend: 'Ext.data.Model',

    fields: [{
        name: 'field1',
        type: 'string'
    }],

    getField1: function() {
        return this.data.field1;
    },

    setField1: function(field1) {
        this.set('field1', field1);
    },
});

如何覆盖它并添加额外的字段 ```field3``

例如,如何覆盖以下 class 并添加额外的字段?

Ext.define('Ext.calendar.model.Event', {
    extend: 'Ext.data.Model',

    mixins: ['Ext.calendar.model.EventBase'],

    fields: [{
        name: 'title',
        type: 'string'
    }, {
        name: 'color',
        type: 'string'
    }],

    getColor: function() {
        return this.data.color;
    },

    getTitle: function() {
        return this.data.title;
    },

    setColor: function(color) {
        this.set('color', color);
    },

    setTitle: function(title) {
        this.set('title', title);
    }
});

我试过了

我不明白你为什么需要这个,但无论如何:

Ext.define('Mypp.model.Class1', {
    extend: 'Ext.data.Model',

    fields: [{
        name: 'field1',
        type: 'string'
    }],

    getField1: function() {
        return this.data.field1;
    },

    setField1: function(value) {
        this.set('field1', value);
    },
});

Ext.define('overrides.model.Class1', {
    override: 'Mypp.model.Class1',

    fields: [{
        name: 'field1',
        type: 'string'
    }, {
        name: 'field2',
        type: 'string'
    }],

    getField2: function() {
        return this.get('field2');
    },

    setField2: function(value) {
        this.set('field2', value);
    }
});

model = new Mypp.model.Class1();
model.setField1('Field1Value');
model.setField2('Field2Value');
console.log(
    model.getField1(),
    model.getField2()
);