1. #1
    Touch Premium Member
    Join Date
    Sep 2011
    Posts
    7
    Vote Rating
    0
    remeis is on a distinguished road

      0  

    Default Override of Ext.data.Model

    Override of Ext.data.Model


    Hi community,

    I'm using Ext 4.0.7 and want to dynamically add columns to a grid view. Therefore, I also have to modify the connected store and model definitions. While fighting with the code I thougth it might work if I simply override the existing model and add some new fields.

    Consider the following model:
    Code:
    Ext.define('myModel', {
      extend: 'Ext.data.Model',
      fields: [
        { name: 'title', type: 'string', defaultValue: '' }
      ]
    });
    Now let's override the model:
    Code:
    Ext.override(myModel, {
      fields: [
        { name: 'title', type: 'string', defaultValue: '' },
        { name: 'subtitle', type: 'string', defaultValue: '' }
      ]
    });
    This did work, but if I then want to create a new model instance by
    Ext.create('myModel');
    I get the following error:

    fields is undefined
    [Break On This Error]
    length = fields.length;


    However, I solved that issue by redefining the model and extending from itself:
    Code:
    Ext.define('myModel', {
      extend: 'myModel',
      fields: [
        { name: 'title', type: 'string', defaultValue: '' },
        { name: 'subtitle', type: 'string', defaultValue: '' }
      ]
    });
    Can someone please tell me, why the override did not work or where I did a mistake?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,994
    Vote Rating
    846
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    The fields are used in the onClassExtended method of Ext.data.Model so they are only used when they are extended.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1