1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    10
    Answers
    1
    Vote Rating
    1
    curmil is on a distinguished road

      0  

    Default Answered: STB2, JSON data in DataStore.Raw but not in DataStore.Data

    Answered: STB2, JSON data in DataStore.Raw but not in DataStore.Data


    I tried to update to B2, but my jsonp stores stopped loading the fetched data into the associated models. It worked in B1 and below, but not in B2.

    my model
    Code:
    Ext.define('MyApp.model.Post', {
        extend: 'Ext.data.Model',
        config: {
            idProperty: 'localId',
            fields: [
                {name: "localId", type: "auto"},
                {name: "id", type: "int"},
                ...
                {name: "text", type: "string"},
                ...
            ],
            proxy: 'posts',
        },
    });
    my local proxy
    Code:
    Ext.define('MyApp.proxy.Posts', {
        extend  : 'Ext.data.proxy.LocalStorage',
        alias: 'proxy.posts',
        config: {
            id: 'localposts',
            model: 'MyApp.model.Post',
        }
    })  ;
    my remote store
    Code:
    Ext.define('MyApp.store.RemotePosts', {
        extend  : 'Ext.data.Store',
        config: {
            id: 'RemotePosts',
            model: 'MyApp.model.Post',
            remoteFilter: true,
            proxy: {
                type: 'jsonp',
                url: 'http://mydomain.com/post/fetch',
                reader: {
                            type: 'json',
                            root: 'results'
                        },
                   },
        },
    });
    when my view initializes
    Code:
                var remotePosts = Ext.create('MyApp.store.RemotePosts', {
                    remoteFilter: true,
                    filters: filters,
                });
    
    
                remotePosts.load({
                    callback: function(records, operation, success) {
                        for (i in records) {
                            var currentRecord = records[i];
                                                    ...
                        }
                    }
                });
    Here is what the records variable looks like in chrome. As you can see the data is in the raw results but not in the data itself.
    Code:
    • 0: Ext.apply.create.Class
      • _data: Object
      • data: Object
        • id: null
        • localId: "ext-record-12"
        • ...
        • text: null
        • __proto__: Object
      • id: "ext-record-12"
      • internalId: "ext-record-12"
      • modified: Object
      • phantom: true
      • raw: Object
        • next_page: "?page=2&max_id=164575332152774658&q=my+search"
        • page: 1
        • refresh_url: "?page=2&max_id=164575332152774658&q=my+search"
        • results: Array[17]
          • 0: Object
            • id: "144221157757947904"
            • id_str: "144221157757947904"
            • text: "Some Text"
            • ...
            • __proto__: Object
          • 1: Object
          • ...
    Any ideas?

    This has been reported in Ext JS 4 as well, but there's been no answer and since it only happens in B2, I figured I could get a better answer here.

    http://www.sencha.com/forum/showthre...DataStore.Data

  2. I figured it out, the root property in the reader needed to be changed to rootProperty, so this:


    Code:
    Ext.define('MyApp.store.RemotePosts', {
        extend  : 'Ext.data.Store',
        config: {
            id: 'RemotePosts',
            model: 'MyApp.model.Post',
            remoteFilter: true,
            proxy: {
                type: 'jsonp',
                url: 'http://mydomain.com/post/fetch',
                reader: {
                            type: 'json',
                            root: 'results'
                        },
                   },
        },
    });
    became

    Code:
    Ext.define('MyApp.store.RemotePosts', {
        extend  : 'Ext.data.Store',
        config: {
            id: 'RemotePosts',
            model: 'MyApp.model.Post',
            remoteFilter: true,
            proxy: {
                type: 'jsonp',
                url: 'http://mydomain.com/post/fetch',
                reader: {
                            type: 'json',
                            rootProperty: 'results'
                        },
                   },
        },
    });

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,604
    Answers
    3450
    Vote Rating
    818
    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


    How many records are returned in your load callback?

    Also, the data property shouldn't be used, the _data property is the one to use.
    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.

  4. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    10
    Answers
    1
    Vote Rating
    1
    curmil is on a distinguished road

      0  

    Default


    The store returns a record set with a single record in it. That record has no data in the data or _data properties except for the id attribute (localId). The actual 17 records that should have been in the recordset exist in the raw property of the single record.

  5. #4
    Sencha User
    Join Date
    Oct 2011
    Posts
    10
    Answers
    1
    Vote Rating
    1
    curmil is on a distinguished road

      0  

    Default


    I figured it out, the root property in the reader needed to be changed to rootProperty, so this:


    Code:
    Ext.define('MyApp.store.RemotePosts', {
        extend  : 'Ext.data.Store',
        config: {
            id: 'RemotePosts',
            model: 'MyApp.model.Post',
            remoteFilter: true,
            proxy: {
                type: 'jsonp',
                url: 'http://mydomain.com/post/fetch',
                reader: {
                            type: 'json',
                            root: 'results'
                        },
                   },
        },
    });
    became

    Code:
    Ext.define('MyApp.store.RemotePosts', {
        extend  : 'Ext.data.Store',
        config: {
            id: 'RemotePosts',
            model: 'MyApp.model.Post',
            remoteFilter: true,
            proxy: {
                type: 'jsonp',
                url: 'http://mydomain.com/post/fetch',
                reader: {
                            type: 'json',
                            rootProperty: 'results'
                        },
                   },
        },
    });

  6. #5
    Sencha User
    Join Date
    Aug 2011
    Location
    Miami, Florida
    Posts
    24
    Vote Rating
    -1
    tmort is an unknown quantity at this point

      0  

    Default


    Thank you! You saved me from two more‚Äč hours of scratching my head.

Thread Participants: 2