Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha Premium Member
    Join Date
    Feb 2009
    Posts
    309
    Vote Rating
    2
    azuroff will become famous soon enough

      0  

    Default [CLOSED]Field mapping property ignored when creating Model instance

    [CLOSED]Field mapping property ignored when creating Model instance


    If you have a Model where the "mapping" property is defined for the model's fields, that property appears to be ignored when an instance of the Model is created.

    Here's a simple test case that shows exactly what happens:

    Code:
    Ext.define('User', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'firstName', type: 'string', mapping: 'FIRST_NAME'},
            {name: 'lastName', type: 'string', mapping: 'LAST_NAME'}
        ]
    });
    
    var store = new Ext.data.Store({
        model: 'User',
        data: [{
            "FIRST_NAME": 'Ed',
            "LAST_NAME": 'Spencer'
        }, {
            "FIRST_NAME": 'Tommy',
            "LAST_NAME": 'Maintz'
        }, {
            "FIRST_NAME": 'Jamie',
            "LAST_NAME": 'Avins'
        }]
    });
    
    console.dir(store.data.items[0].data);
    Here's the code from the Model.js constructor that checks to see if data for each field is already present and sets a default value if not:


    Code:
    //add default field values if present
            var fields = this.fields.items,
                length = fields.length,
                field, name, i;
    
            for (i = 0; i < length; i++) {
                field = fields[i];
                name  = field.name;
    
                if (data[name] === undefined) {
                    data[name] = field.defaultValue;
                }
            }
    And here's a fix that takes the mapping into account:

    Code:
            //add default field values if present
            var fields = this.fields.items,
                length = fields.length,
                field, name, mapping, i;
            
            for (i = 0; i < length; i++) {
                field = fields[i];
                name  = field.name;
                mapping = field.mapping;
                
                if (data[name] === undefined) {
                    if (mapping && data[mapping] !== undefined) {
                        data[name] = data[mapping];
                        delete data[mapping];
                    } else {
                        data[name] = field.defaultValue;
                    }
                }
            }

  2. #2
    Sencha Premium Member
    Join Date
    Feb 2009
    Posts
    309
    Vote Rating
    2
    azuroff will become famous soon enough

      0  

    Default


    Never mind... (I think)

    It looks like running the data through a JsonReader before loading it into the store uses the field mappings properly...

    Code:
            Ext.define('User', {
                extend: 'Ext.data.Model',
                fields: [
                    {name: 'firstName', type: 'string', mapping: 'FIRST_NAME'},
                    {name: 'lastName', type: 'string', mapping: 'LAST_NAME'}
                ]
            });
    
            var data = [{
                "FIRST_NAME": 'Ed',
                "LAST_NAME": 'Spencer'
            }, {
                "FIRST_NAME": 'Tommy',
                "LAST_NAME": 'Maintz'
            }, {
                "FIRST_NAME": 'Jamie',
                "LAST_NAME": 'Avins'
            }];
    
            var store = new Ext.data.Store({
                model: 'User'
            });
    
            var reader = new Ext.data.JsonReader({
                model: 'User'
            });
    
            store.loadData(reader.readRecords(data).records);
            console.dir(store.data.items[0].data);
    It looks like store.loadData() still doesn't work with raw JSON data even if you configure a MemoryProxy with a JsonReader in the store, but I can live with explicitly creating a JsonReader for what I need to do.

Similar Threads

  1. Replies: 9
    Last Post: 5 Sep 2011, 4:13 PM
  2. [FIXED-114] Creating new instance of Model results in "dirty" object
    By jeroenvduffelen in forum Sencha Touch 1.x: Bugs
    Replies: 8
    Last Post: 23 Feb 2011, 6:05 PM
  3. Replies: 4
    Last Post: 9 Sep 2010, 12:27 PM
  4. [CLOSED] Model instance get's parent Store as object after inserting
    By jeroenvduffelen in forum Sencha Touch 1.x: Bugs
    Replies: 1
    Last Post: 20 Jul 2010, 7:23 AM
  5. Replies: 4
    Last Post: 2 Jan 2008, 3:17 PM

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar