Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : I can't get my view to work, it doesn't do anything at all.

$
0
0
Thank you very much for your tips. I used your script and edited it a bit and now it works. Though I still don't understand why they use loops in the Todo-tutorial if it is not a bad practice. And I still don't understand why my original method doesn't work, even though it might not be a best practice. This is my current code that seems to do the job:

  1. function renderContents($element, Blocks, Containers) {
  2. var count = Blocks.length + Containers.length;
  3. var $newElement;
  4. var b = 0; var c = 0;
  5. for(var i=0; i < count; i++){
  6. if (typeof Blocks[b] !== "undefined" && parseInt(Blocks[b].BlocksPage.index) <= i) {
  7. $element.append($.View("//view/block.ejs", Blocks[b]));
  8. b++;
  9. } else {
  10. $newElement = $(document.createElement('div')).model(Containers[c]);
  11. renderContents($newElement, Containers[c].Blocks, Containers[c].Containers);
  12. $element.append($newElement);
  13. c++;
  14. }
  15. }
  16. }

  17. Page.findOne({id: <?=$page['id']?>}, function( page ){
  18. // print out the todo name
  19. console.log(page);
  20. $('body').model(page.Layout);
  21. renderContents($('body'), page.Layout.Blocks, page.Layout.Containers);
  22. $('html').model(page);
  23. $('.cake-sql-log').appendTo('body');
  24. //$('body').html('//view/layout.ejs', page.Layout);
  25. });

Viewing all articles
Browse latest Browse all 3491

Trending Articles