Results 1 to 2 of 2

Thread: [4.1 Beta 2] Model conversion changes now cause failures if a field is named "source"

    Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #1
    Ext JS Premium Member
    Join Date
    Nov 2009
    Location
    St Louis,MO
    Posts
    267
    Vote Rating
    18
      0  

    Default [4.1 Beta 2] Model conversion changes now cause failures if a field is named "source"

    REQUIRED INFORMATION
    Ext version tested:

    • Ext 4.1 Beta 2

    Browser versions tested against:

    • Chrome 16.0.912.75

    DOCTYPE tested against:

    • html

    Description:

    • Model conversion changes now cause failures if a field is named "source" and has a type. This worked fine in 4.0.X and in 4.1 Beta 1.

    Steps to reproduce the problem:

    • Load enclosed script

    The result that was expected:

    • No errors

    The result that occurs instead:

    • Uncaught TypeError: Object #<Object> has no method 'convert'

    Test Case:
    Code:
    <!DOCTYPE html>
    <html>
       <head>
          <title id="page-title">ExtJS 4.1 Bug</title>
          <link rel="stylesheet" type="text/css" href="js/extjs/resources/css/ext-all.css" />
          <script type="text/javascript" src="js/extjs/ext-all-debug.js"></script> 
          <script type="text/javascript" src="js/extjs/examples/ux/SlidingPager.js"></script> 
    
    
    
    
          <script type="text/javascript">
                Ext.onReady(function() {
                   Ext.define ('Test', {
                      extend: 'Ext.data.Model',
                      fields: [ 'id', { name: 'source', type: 'string' } ],
                   });
                   var store = Ext.create ('Ext.data.Store', {
                      model: 'Test',
                      data: {
                         records: [
                            { id: 1, source: 'foo' },
                            { id: 2, source: 'bar' }
                         ]
                      },
                      proxy: {
                         type: 'memory',
                         reader: {
                            type: 'json',
                            root: 'records'
                         }
                      }
                   });
                });
          </script>
       </head>
       <body>
       </body>
    </html>
    HELPFUL INFORMATION
    Debugging already done:
    The bug is in the generated model conversion code. Reader.extractData calls:
    Code:
    me.convertRecordData(convertedValues, node, record);
    which is generated code that looks like:
    Code:
    var me = this,
        fields = me.model.prototype.fields,
        value,
        internalId,
        id = fields.get("id"),
        source = fields.get("source");
    
    
        return function(dest, source, record) {
            dest.id = (source["id"] === undefined) ? id.defaultValue : source["id"];
            dest.source = source.convert((source["source"] === undefined) ? source.defaultValue : source["source"], record);
            if (internalId = source["clientId"]) {
                record.internalId = internalId;
            }
        };
    })
    Notice that dest.source calls source.convert which is using the function local scope source and not the closure source variable defined above the function. Again, this worked in 4.0.X and 4.1 Beta 1 so if source is now a data model keyword that is new.
    Possible fix:
    • rename the arguments to "function" to be something almost guaranteeed to be uniqe. Source is pretty common for a data variable name.
    • make the fields an object as in var me = this...fields = { source: fields.get("source")... so that the the conversion becomes ...fields.source.convert((source["source"]...

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    18,427
    Vote Rating
    858
      0  

    Default

    It's essentially a manifestation of this issue, so I'll roll all the fixes up into that.

    http://www.sencha.com/forum/showthre...s-model-fields
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •