View Full Version : XTemplates + Data Stores
bortron5000
23 Jan 2012, 9:55 PM
Hey all,
Hope this isn't super basic and obvious, but I was wondering the best way to use XTemplates if all I have is access to a store. It seems like you need to pass a pretty raw data object in for an XTemplate to work, so is there a good way to parse the store down to just it's data as an object? Again, I apologize if this is incredibly easy, I've been messing around with it and can't seem to figure it out.
mitchellsimoens
24 Jan 2012, 7:04 AM
You can iterate through the store to create an array of objects:
var recs = store.getData().items, //get all records
r = 0,
rNum = recs.length,
data = [];
for (; r < rNum; r++) {
data.push(recs[r].getData()); //grab the data object off the rec and push to data array
}
Just typing off the top of my head and trying to think of the new stuff in PR4 at the same time. You should get the idea at least though.
I do have a similar question:
We used to be able to use Ext.DataView for that exact purpose, but since the "tpl" option in DataView was deprecated in favor of "itemTpl" (also see this thread (http://www.sencha.com/forum/showthread.php?160429-Dataview-itemtpl-vs-tpl&)) the DataView component is basically the same as List without default styling.
Is there any way the old DataView functionality, i.e. loading structured data from a store and applying it directly to a template without a bloated DOM, is coming back in some form?
bortron5000
24 Jan 2012, 7:49 AM
This did the trick, thanks. I thought there might be something built in (sounds from the other post like there once was) but this method is simple enough.
One interesting thing I noticed using the XTemplate, if I put in an <hr> tag (horizontal line) to divide up the different templated sections, it appears as a vertical line, and the text blocks become separated laterally as opposed to vertically! Quite the opposite of what I was expecting...
jay@moduscreate.com
25 Jan 2012, 4:39 PM
I would elect to use a data view. It does * a lot * of the work for you.
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.