Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-5677 in 4.1.2.
  1. #1
    Sencha User
    Join Date
    Sep 2011
    Posts
    11
    Vote Rating
    0
    mom_vincent is on a distinguished road

      0  

    Default [4.0.7] metaData is not read in wrapped JSON (ASP.NET)

    [4.0.7] metaData is not read in wrapped JSON (ASP.NET)


    ASP.NET tends to wrap JSON responses with a "d" property e.g.

    Code:
    {"d":{
        "metaData": {
            "root": "data",
            "fields": [{
                "type": "int",
                "name": "id",
                "hidden": true,
                "header": "id",
                "groupable": false,
                "dataIndex": "id"
            }, ...omitted for brevity...]
        },
        "success": true,
        "data": [{
            "id": "1",
            "controller": "Permissions",
            "description": "Allow to see permission by roles",
            "administrator": true,
            "marketing": false
        }]
      }  
    }
    Unfortunately there is no simple way around this. There is a reason behind the madness (I believe it's to do with a specific JS injection attack). So we ASP.NET devs try to live with it.

    This is normally not an issue with EXTJS as one can set the root of the data in the proxy's reader of the store. However this does not apply to reading the metaData of a JSON response.

    The reason is that the method 'readRecords' does not check if the metaData exists on a lower nested level (it is assumed the metaData exists on the top level of the response). So for example when trying to reconfigure a grid's columns the metaData is never read, so a bunch of rows will appear but the actual data will not.

    A working solution is to use the 'getRoot()' function of the Reader to always get the defined root of the data. Here's my override:
    Code:
    Ext.override(Ext.data.reader.Json, {
        readRecords: function (data) {
            //this has to be before the call to super because we use the meta data in the superclass readRecords
            if (this.getRoot(data).metaData) {
                this.onMetaChange(this.getRoot(data).metaData);
            }
    
    
            /**
            * @deprecated will be removed in Ext JS 5.0. This is just a copy of this.rawData - use that instead
            * @property {Object} jsonData
            */
            this.jsonData = data;
            return this.callParent([data]);
        }
    });
    Hope this helps

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,142
    Vote Rating
    855
    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


    Sounds reasonable. Just a little optimization on your code, I would put this.getRoot(data) onto a variable so you don't have to do the execution twice.
    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