BorisMoore / jquery-tmpl

The original official jQuery Templates plugin. This project was maintained by the jQuery team as an official jQuery plugin. It is no longer in active development, and has been superseded by JsRender.
3.23k stars 1.01k forks source link

update() loses associated tmplData #123

Closed warappa closed 13 years ago

warappa commented 13 years ago

When a template element is updated, the data associated with the element is lost (more specific: the whole jQuery data object is lost).

$(this).tmplItem().data; // returns associated model fragment
// manipulate data
$(this).tmplItem().update(); // update renderes template with the updated data
// data gets rendered correctly
$(this).tmplItem().data; // data is empty!

Result: Data is empty.

Expected: Data should be preserved.

Lg warappa

BorisMoore commented 13 years ago

update renders the template, so the element this will be removed from the DOM when you call update. Therefore $(this).tmplItem() will not be what you want on the next line.

var item = $(this).tmplItem()
item.data; // returns associated model fragment
// manipulate data
item.update(); // update renderes template with the updated data
// data gets rendered correctly
var test = item.data; // data is not empty!