Results 1 to 6 of 6

Thread: 4.1 Beta 2 - Json reader and createAccessor

  1. #1
    Touch Premium Member
    Join Date
    Jan 2008
    Location
    Quebec, Canada
    Posts
    136
    Vote Rating
    5
      0  

    Exclamation 4.1 Beta 2 - Json reader and createAccessor

    Hi,

    I'm trying to test my application in the Beta 2 and I have a question regarding the internals of the Json reader.

    Previously, I overrided the method "createAccessor" for custom needs. Now the method is still there but there is the new one "createFieldAccessExpression" which has the same documentation but seems to be called elsewhere.

    What is exactly the purpose of this new function and why not merge the two ?

  2. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,060
    Vote Rating
    1389
      0  

    Default

    It looks like createFieldAccessExpression is for mapping of fields to response fields.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  3. #3
    Touch Premium Member
    Join Date
    Jan 2008
    Location
    Quebec, Canada
    Posts
    136
    Vote Rating
    5
      0  

    Default

    Ok I see ... now a function is builded as a string to extract data. Want I want is a "NullSafe" json extractor.
    For example, if mapping is user.description, I want to handle the fact that "user" can be null...

    I don't know how to achieve this in the new format ... my old custom function was doing something like this :
    Code:
                        var parts = expr.split('.');
                        return function(value) {
                            for (var i =0; i < parts.length; i++) {
                                if (!value)
                                    return null;
                                value = value[parts[i]];
                            }
                            return value;
                        };

  4. #4
    Sencha User dongryphon's Avatar
    Join Date
    Jul 2009
    Location
    Kansas
    Posts
    1,742
    Vote Rating
    258
      0  

    Default

    Can you use a converter for the field?

    http://dev.sencha.com/deploy/ext-4.0...ld-cfg-convert
    Don Griffin

    "Use the source, Luke!"

  5. #5
    Sencha User dongryphon's Avatar
    Join Date
    Jul 2009
    Location
    Kansas
    Posts
    1,742
    Vote Rating
    258
      0  

    Default

    A converter, if it can achieve your goals, is much better than operating on the private methods behind the reader. Obviously, one has to do what one has to do...
    Don Griffin

    "Use the source, Luke!"

  6. #6
    Ext JS Premium Member
    Join Date
    Jan 2008
    Posts
    27
    Vote Rating
    1
      0  

    Default

    I've just had the same kind problem during my migration from 4.0.7 to 4.1.0

    Here is the convert function that I wrote to address this behaviour :
    Code:
        var jsonNullSafe = function(field, prop) {
            return function(v, record) {
                var json = record.get(field) || {},
                    value = json[prop];
                return value || v;
            }
        };
    
        Ext.define('Book', {
            extend: 'Ext.data.Model',
            fields: [{
                name: 'title'
            }, {
                name: 'author'
            }, {
                name: 'authorFirstName',
                convert: jsonNullSafe('author', 'fn')
            }, {
                name: 'authorLastName',
                convert: jsonNullSafe('author', 'ln')
            }]
        });
    In 4.0.7 my model was :
    Code:
        Ext.define('Book', {
            extend: 'Ext.data.Model',
            fields: [{
                name: 'title'
            }, {
                name: 'authorFirstName',
                mapping: 'author.fn'
            }, {
                name: 'authorLastName',
                mapping: 'author.ln'
            }]
        });

Posting Permissions

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