locked
Template.renderItem method

    Question

  • Hello guys.

    After reading the docs, I'm still not clear on when I should this method instead of render. Any ideas?

    thanks


    Luis Abreu

    Friday, March 30, 2012 9:33 AM

All replies

  • I took a look at the docs and binding.js.

    This from the docs pretty much sums it up:

    Renders an instance of this template bound to the data contained in item. If the recycled parameter is present, and enableRecycling is true, then the template attempts to reuse the DOM elements from the recycled parameter.

    What is really confusing is that the last parameter is NOT a boolean as it is documented but should be a previously generated DOM Element that matches the template.  I could not find any sample that uses this but how I imagine it may work is if you are changing the data you were displaying in the template (and it was not occuring multiple times) you could pass the DOM Element you created the first time you rendered the template.

    recycled

    Type: DOM Element

    A previously-generated template instance.


    Jeff Sanders (MSFT)

    Friday, March 30, 2012 8:23 PM
    Moderator
  • Hello again Jeff.

    Oh I see. If the idea is to reuse some previously generated HTML instead of recreating a new one, then it should be slight fast. I'll have to write a test for it, but if it works like I think, then this is what I should be using for my edit form. Since it shows only one record at the time but since it allows me to navigate between records, then refreshing the UI when navigating between should probably be done by renderItem instead of render.

    I'l give it a go and then I'll provide some more info here.


    Luis Abreu

    Sunday, April 01, 2012 2:26 PM
  • Well , it seems like there's more to it than it seems at first look.

    For instance, I can't seem to reuse the HTML element because its msOriginalTemplate property is not set. 

    I've tried generating a template through the render method and reusing that HTML generated on the next renderItem call, but it simply didn't work.

    So, more ideas on how to use this?


    Luis Abreu

    Monday, April 02, 2012 11:31 AM
  • *bump*

    anyone?


    Luis Abreu

    Monday, April 09, 2012 2:17 PM