Results 1 to 5 of 5

Thread: XTemplates + Data Stores

  1. #1
    Touch Premium Member
    Join Date
    Nov 2011
    Posts
    37
    Vote Rating
    0
      0  

    Question 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    49
    Vote Rating
    0
      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
      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 User jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364
    Vote Rating
    86
      0  

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •