1. #1
    Sencha User
    Join Date
    Jan 2011
    Posts
    10
    Vote Rating
    0
    hofo is on a distinguished road

      0  

    Default Store filter root property in nested JSON?

    Store filter root property in nested JSON?


    Hi,

    I'm loading a store with JSON that looks like :

    Code:
    {
       "SUCCESS":true,
       "RESPONSE":{
          "CONTENTOBJECTS":[
             {
                "CONTENTGROUP":"1",
                "CONTENTTITLE":"promote test 1 title",
                "OBJECTID":"C49B8765-1C80-0001-EA62-1A031F8F262",
             },
             {
                "CONTENTGROUP":"2",
                "CONTENTTITLE":"December Brings Measured Improvements in Southeast Economy",
                "OBJECTID":"C51E7E07-4860-0001-467B-E7361D97AC5",
             }
          ],
          "CONTENTGROUPS":[
             "News",
             "Podcasts"
          ]
       }
    }
    If I want to apply a filter to the store to get only items that have CONTENTGROUP of "2", what do I do? I've tried setting it on the store and the data won't load with it. Do I need to set the root on the filter?

    Here's the store:

    Code:
    Ext.define('FRBAMobile.store.ContentObjects', {    extend: 'Ext.data.Store',
        requires: [
            'FRBAMobile.model.ContentObject'
        ],
    
    
        config: {
            autoLoad: true,
            model: 'FRBAMobile.model.ContentObject',
            storeId: 'ContentObjects',
            proxy: {
                type: 'jsonp',
                url: 'http://devserver/mobileContent/',
                reader: {
                    type: 'json',
                    rootProperty: 'RESPONSE.CONTENTOBJECTS',
                    successProperty: 'SUCCESS'
                }
            },
            filters: [
                {
                    id: 'contentGroup1Filter',
                    property: 'CONTENTGROUP',
                    value: "1"
                }
            ]
        }
    });

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,624
    Vote Rating
    434
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    What does the model look like?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    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 almost in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jan 2011
    Posts
    10
    Vote Rating
    0
    hofo is on a distinguished road

      0  

    Default


    Here 'tis:

    Code:
    Ext.define('FRBAMobile.model.ContentObject', {
        extend: 'Ext.data.Model',
        config: {
            fields: [
                {
                    name: 'OBJECTID',
                    type: 'string'
                },
                {
                    name: 'CONTENTTITLE',
                    type: 'string'
                },
                {
                    allowNull: false,
                    defaultValue: '1',
                    name: 'CONTENTGROUP'
                },
                {
                    name: 'BODY'
                },
                {
                    name: 'MOBILEBODY'
                }
            ]
        }
    });

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,624
    Vote Rating
    434
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    What I am getting is if you have the filters, it has a count of 1. If you remove the filters config it has a count of 2 so looks like your code is working for me. The only thing I did was change the proxy from jsonp to ajax as I was just loading off a JSON file.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    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 almost in print!

    When posting code, please use BBCode's CODE tags.