1. #1
    Touch Premium Member
    Join Date
    Nov 2011
    Posts
    37
    Vote Rating
    0
    bortron5000 is on a distinguished road

      0  

    Question XTemplates + Data Stores

    XTemplates + Data Stores


    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.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    871
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You can iterate through the store to create an array of objects:

    Code:
    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.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

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

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    49
    Vote Rating
    0
    j.k is on a distinguished road

      0  

    Default


    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) 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?

  4. #4
    Touch Premium Member
    Join Date
    Nov 2011
    Posts
    37
    Vote Rating
    0
    bortron5000 is on a distinguished road

      0  

    Default


    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...

  5. #5
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364
    Vote Rating
    81
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    I would elect to use a data view. It does * a lot * of the work for you.