1. #1
    Sencha User
    Join Date
    Oct 2013
    Posts
    4
    Vote Rating
    0
    niklasro is on a distinguished road

      0  

    Default Unanswered: How to extend jsonreader?

    Unanswered: How to extend jsonreader?


    I have an overly nested json that I want to render and I think that the only way, since I can't change the json input, is to extend the json reader and override the reading. My json looks like this:
    Code:
    {
        "productOfferings": [
            {
                "name": "A Product Offering name",
                "description": "A Product Description",
                "productOfferings": [
                    {
                        "id": 5,
                        "name": "A Product Offering name, id 5",
                        "description": "A Product Offering description, id 5",
                        "productSpecification": {
                            "id": 3,
                            "name": "A Product Specification id 3",
                            "description": ""
                        }
                    },
                    {
                        "id": 8,
                        "name": "A Product Offering name, id 8",
                        "description": "A Product Offering description, id 8",
                        "productSpecification": {
                            "id": 9,
                            "name": "A Product Specification id 9",
                            "description": "A Product Description id 9",
                            "productSpecifications": [
                                {
                                    "id": 2,
                                    "name": "A Product Specification id 2",
                                    "description": "A Product Description id 2"
                                },
                                {
                                    "id": 4,
                                    "name": "A Product Specification id 4",
                                    "description": "A Product Description id 4"
                                }
                            ]
                        }
                    }
                ]
            }
        ]
    }
    And I wonder how to extend the jsonreader in Sencha Architect to be able to render this structure. I've seen it done in a fiddle: http://jsfiddle.net/Izhaki/fF5Ux/

    A
    nd I want to try something similar e.g.

    Code:
     Ext.define('MyReader', {        extend : 'Ext.data.reader.Json',        alias : 'reader.myreader',            buildExtractors : function()    {        var me = this;        me.callParent(arguments);        me.getRoot = function ( aObj ) {            // Special case           if aObj[ 'productOfferings' ] == null {              return aObj[ 'productSpecification' ];            }                                        // Default root is `productOfferings`            return aObj[ 'productOfferings' ];        };    }    });
    But how do I achieve this in Sencha Architect? I don't find a way to extend the jsonreader lika above in Sencha Architect. Can you help me?

  2. #2
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    23
    Answers
    2
    Vote Rating
    2
    Scott-1 is on a distinguished road

      0  

    Default


    You extend the reader by over-riding it in the model or the store.

    ,reader: {
    idProperty : 'id',
    root : '',
    read : function(response){
    return response;
    }
    }

  3. #3
    Sencha User
    Join Date
    Oct 2013
    Posts
    4
    Vote Rating
    0
    niklasro is on a distinguished road

      0  

    Default


    Thank you for the answer but I would like more detail. When I try to create an override the IDE complains and I don't think that I did it correctly.

    complain.png

Thread Participants: 1

Tags for this Thread