twigkit / tempo

Tempo is an easy, intuitive JavaScript rendering engine that enables you to craft data templates in pure HTML.
http://tempojs.com/
Apache License 2.0
709 stars 73 forks source link

Too many template iterations #75

Closed malpaso closed 11 years ago

malpaso commented 11 years ago

Hi,

I have the following JSON data.

[{"price":"5.0000","name":"Test Dry Dog Food","guid":"AC6D5C24-F4EC-38DB-A273-86681F2B64DC","id":"1","image_secondary":"","image_primary":"","image_thumbnail":""}]

A simple Tempo.prepare(id).render(data) with this JSON renders correctly, however when the data is returned from the server via ajax, it iterates 163 times on the above data.

The data response from the server (in Chrome Dev Tools) looks like this:

"[{\"price\":\"5.0000\",\"name\":\"Test Dry Dog Food\",\"guid\":\"AC6D5C24-F4EC-38DB-A273-86681F2B64DC\",\"id\":\"1\",\"image_secondary\":\"\",\"image_primary\":\"\",\"image_thumbnail\":\"\"}]" 
difrnt commented 11 years ago

Prior to re-rendering the object you may want to call the tempo .clear() function. It should do this automatically, but this should guarantee it's cleared.

Here's the example from the tempojs.com site:

Tempo.prepare('marx-brothers').render( data ).clear();
malpaso commented 11 years ago

Thx @difrnt I actually figured out the error. I had to use $.parseJSON() on my return string, apologies for the bother.

mrolafsson commented 11 years ago

Thanks Matt for the help debugging - I really appreciate it!