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

Re : How to remove controllers without deleting the parent Element?

$
0
0
With nested controls I usually do something like this:
  1. can.Control({
  2.       init: function(el, options){
  3.             this.section = new SectionControl(this.element.find('.section'), {});
  4.       },
  5.       'blog route': function() {
  6.             this.section && this.section.destroy();
  7.             this.section = new BlogControl(this.element.find('.section'), {});
  8.       }
  9. })
So when the route changes, destroy any existing Control. Like Curtis said this will let it be Garbage collected. Then just assign the new Control to that instance variable. Because the different Controls usually render their own views on their element you wouldn't have to worry about removing any DOM elements either.

Viewing all articles
Browse latest Browse all 3491

Trending Articles