PDA

View Full Version : Assign a datastore for an XTemplate to use???



Trok1
5 Aug 2010, 10:12 AM
Hi All,

I am trying to assign a datastore to be used in an xtemplate. I do a switch to determine which datastore to use. The datastore is loaded with data and ready to be used. Im not sure how to do this properly. It does not work as illustrated below.


case 'carousel':
var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<p>ID: {carousel_id}</p>',
'<p>Title: {title}</p>',
'<p>Text: {text}</p>',
'</tpl>'
);
var dataObj = Ext.StoreMgr.get('assetCarouselStore');
tpl.overwrite(Ext.getCmp('assetPreview').body, dataObj.data);
break;


thank you,

Todd

Trok1
5 Aug 2010, 10:52 AM
Newbie mistake. I got it to work by the following:

tpl.overwrite(Ext.getCmp('assetPreview').body, dataObj.data.items[0].data);

is this ok? Or is there a more elegant way to do this?

Thanks

Trok1
5 Aug 2010, 11:15 AM
My Final output:

case 'carousel':
var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<p>ID: {carousel_id}</p>',
'<p>Title: {title}</p>',
'<p>Text: {text}</p>',
'</tpl>'
);

var assetId = record.data.asset_id;
var activeRecord = assetCarouselStore.find('carousel_id', assetId, 0 , false, false);
var Record = assetCarouselStore.getAt(activeRecord).data ;
tpl.overwrite(Ext.getCmp('assetPreview').body, Record );

aconran
12 Aug 2010, 3:37 PM
Take a look at the DataView component which binds together an XTemplate and an Ext.data.Store with your own custom markup.