PDA

View Full Version : Shared stores and store roots



smick
3 Nov 2010, 12:07 PM
Hi again,

I want to use one store for multiple panels in my app, but I can't figure out how to specify which array of the store each panel should have access to.

For example, I have the following store:


search_results = new Ext.data.JsonStore({

root: 'rows',
totalProperty: 'totalCount',
idProperty: 'id',
remoteSort: true,
fields: [
'id',
'more_data',
'Pages'
],
proxy: new Ext.data.HttpProxy({
url: "./data/search_data.php"
}),
});
search_results.setDefaultSort('id', 'desc');
search_results.load({params:{start:0, limit:5}});


it returns this json:



{
"totalCount": 16,
"rows": [
{
"id": "2",
"some_data": "here it is"
"pages": [
{
"id": "123",
"fileName": "imageName.jpg"
},
{
"id": "123",
"fileName": "iname2.png"
},
{
"id": "123",
"fileName": "image3.png"
}
]
}
]
}



I want to use this store in a dataView which looks like this:



pages = new Ext.DataView({

border:false,
store: search_results,
tpl: new Ext.XTemplate(
'<tpl for=".">',
'<img src="'+base_url+'/assets/images/{fileName}">',
'</tpl>',
'<div class="x-clear"></div>'
)
})



So that the data view iterates through the pages for a specific row in the search results store.


I just need to get a handle on how to go about doing this. I appreciate any help with this.

swarm
3 Nov 2010, 2:57 PM
It's your data.

You'll need to change {filename} in the DataView as it's not in the root.

I can't remember how you do this though - might be as simple as {pages.filename} or {pages:filename} or wrapping it in a <tpl for="pages">...

Hope this puts you on the right track...

Condor
4 Nov 2010, 12:35 AM
1. Your field name is 'Pages', but your data property is named 'pages' (I suggest you rename your field to match).

2. Your store doesn't have a 'filename' field; you would have to use a <tpl for="pages"> to access the filename.

smick
4 Nov 2010, 1:41 PM
Hmmm.. But how would I access row[1]'s 'Pages' of the store?

My store actually looks like this:



{
"totalCount": 16,
"rows": [
{
"id": "2",
"some_data": "here it is"
"pages": [
{
"id": "123",
"fileName": "imageName.jpg"
},
{
"id": "123",
"fileName": "iname2.png"
},
{
"id": "123",
"fileName": "image3.png"
}
]
},{

"id": "2",
"some_data": "here it is"
"pages": [
{
"id": "123",
"fileName": "imageName.jpg"
},
{
"id": "123",
"fileName": "iname2.png"
},
{
"id": "123",
"fileName": "image3.png"
}
]
}
]
}

I know using json dot notation with brace arrays, but I don't know how to point to a particular array inside an already 'rooted' store.

Thanks for any help!