New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trouble clearing rendered lists #28
Comments
Hi, thanks for reporting this. I'll look into this and see if spot the problem. I'll keep you posted!! |
Hi sorry for the late reply. This is strange, it works for me. I just did the following with the expected results:
Am I misunderstanding you? |
Thanks for your help. I was able to figure it out. The difference in my code is that the function I was calling included this:
So every time i called my function to load new data, that line above was being executed an additional time on the same container. Instead, If I prepare() the container only once and make reference to that global var inside my function then I can then clear and re-render with no issue. Maybe in your twitter example you could just add a working "refresh" button, which would demonstrate clearing and re-rendering data without re-declaring the wrong functions, so people can avoid issues like this. |
Sure yeah - that's a good idea. I'll add that for 1.5. Glad you worked it out. |
Hi, I have kind of the same problem. I get data from the database and render it in a template, then I adapt the data in the database (delete item) and render this new data (which is a shorter list). Instead of replacing the old data in the template with the new data, the renderer appends the new data after the previous data. var u_lookup_template = Tempo.prepare("u_lookup"); var u_info_template = Tempo.prepare("u_info"); var item_id; /** * Get the list of users from the backend */ callWebservice("","/users",function(data){ var users = $.parseJSON(data); //Render the list of users u_lookup_template.render(users.users); u_lookup_template.clear(); }); /** * Convert dialog div into dialog and hide it * This dialog is a confirmation dialog to delete a user(doctor) */ $('#del_dialog').dialog({ autoOpen: false, width: 'auto', buttons: { "Yes": function() { callWebservice("", "/users/delete/user_id/"+item_id, function(data){ var users = $.parseJSON(data); //Reload the doctor list u_lookup_template.render(users.users); u_lookup_template.clear(); }); $(this).dialog("close"); }, Cancel: function(){ $(this).dialog("close"); } } }); I hope you guys can help me because I don't see what I'm doing wrong. |
Shouldn't you clear() the container before rendering? |
As you can see I clear it after every render I do, so it's the same as clearing it before the next render. I've tried putting the clear before the render too, same problem. |
Yeah I would agree about putting the clear() before rendering. My experience that putting it after yields an empty list in the DOM--as anything that was just rendered gets instantly cleared out. Can you post your non-working code where you have the clear() before the render? |
Hey Brian. Thanks for looking at this with me. An important clue might be that he's using a table in his template. I agree it would be good to get a non-working example of the client code for us to debug. I'll try and replicate it here later tonight. |
Thanks for joining on the issue Brian, here's (part of) the code I'm using. I hope you guys can find a solution quickly cause I have to submit my project soon and I'd really like to keep your templating engine. HTML JavaScript
|
We'll do our best! |
Yeah it definitely has something to do with the table, and might be a Tempo bug? The template wont clear when this is used:
But if I use this instead, it can be cleared and re-rendered just fine
...although its not a proper structure :)mrolafsson, I altered his script slightly to successfully render the test data he provided
|
Hmmm I actually tried changing the clearContainer method to just wipe it (since the template should be in memory anyway). And that seems to do the trick. Isn't that a safe assumption guys? |
I hope this resolution didn't come too late for you. The fix I mentioned yesterday is in the 'dev' branch. |
Unfortunately it did come too late. I had to use Trimpath for some parts of the application but I kept Tempo for the biggest part. I think it could be a good templating engine but it needs to be less fixed to its structure. eg. It would be cool if you check the element itself where the data-template property is set to check if it has a field to fill.
It should be able to get the id from the subitems template instead of the id from the data-template in the ul. |
Sorry to hear that! I'm not sure I completely understand your proposal - are you proposing a change to the 'nested templates' feature? |
Sorry for not being clear. My example was indeed with a nested template but my proposal is about the templates in general.
This example won't work with your actual engine because it searches for {{}} inside the ul, not on the ul itself. |
OK I see. I'll close this issue since the one you're describing is a duplicate of #25 |
This issue needs re-addressing. I had to roll back some of the changes. |
Hi |
Hi, As k33g said, we have the same problem : displaying "tr" items in a table. Here is an example showing the problem, comparing the render between "table" and "ul" : The problem is that the table (tbody) content is not cleared. I think it's because the "data-template" attribute is not in the rendered "tr" elements, so there are not cleared in the "clear" method ! Xavier |
Hey guys, I'll look into this now! Thanks for your feedback. |
Hey, I've added a quick test here: http://jsfiddle.net/unFSh/2/ |
Yes !!! it's ok for me with 2.0-dev branch (i've tested with chrome v19 winxp and FF v12 winxp) |
Has anyone tested this in IE after the fix? |
Hey guys, I FINALLY think this is fixed. Basically when I clear the container I only remove elements with a |
I'm having issues re-rendering a list with new data that has been already rendered with Tempo. It would be great to see a working example of how you use the clear() in a real context on your site.
I'm rendering a list like this:
Which works the first go around. If I reuse that code to populate the same list with new data from an ajax call, I get a list the same length as the original, and with every item being populated by the last element in the old data (even though I can see the new data coming in fine in the console). So, for example:
This:
-Billboards
-Centennial Exhibition 1876
Turns into this
-Centennial Exhibition 1876
-Centennial Exhibition 1876
This all seems to point to me using the .clear() function. But I've tried putting it in a few different places and I either get the same result as above or I get an empty list.
Your example seems to suggest chaining it after rendering:
But wouldn't that just clear out the list you just rendered rather than clearing it before you render it?
The text was updated successfully, but these errors were encountered: