PDA

View Full Version : Store filter root property in nested JSON?



hofo
25 Apr 2012, 11:55 AM
Hi,

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


{
"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:


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"
}
]
}
});

mitchellsimoens
27 Apr 2012, 5:36 AM
What does the model look like?

hofo
27 Apr 2012, 9:53 AM
Here 'tis:


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'
}
]
}
});

mitchellsimoens
27 Apr 2012, 10:45 AM
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.