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

How to remove controllers without deleting the parent Element?

$
0
0
let´s assume i have a widget area on my webapp
  1. <div id="widgetbox">
  2.       // my widget goes in here
  3. </div>
then i start a new controller for it, to make this thing happen
  1. weatherWidget = new WeatherWidget("#widgetbox",{}); // ordinary can.Control() extended object
nice, everything works. then i want to "exchange" the widget to another (different) one OR just remove it and leave it blank. so i start to remove this controller. the doc says:
  1. $('#widgetbox').remove();
But then my widget area is gone. where to append the new controller? So i tried different approches
  1. weatherWidget.destroy() // destroys all bindings, nice! but the html is still there
  2. weatherWidget.element.html("") // dont work, because destroy deleted the element/whole control object
another option
  1. weatherWidget.element.html("") // kills html, but events still there
  2. weatherWidget.destroy() // breaks, because element is empty or something
so every way i tried with just the instance doesn´t work. so maybe i have to use hardcore jquery stuff to make this work.

  1. weatherWidget.destroy() // destroys all bindings, nice! but the html is still there
  2. $('#widgetbox').html("") // html cleanup, works!
this works. but only if you have to do this for a few areas. my app is big and i wrote a wrapper around this. this does nothing more than instantiate and destroy controllers. I don´t know if there´s any way to get the initial jQuery select string from the instance to remove all html inside the parent element. Do i am here something wrong? is there a better way to handle many controllers on one page?

Viewing all articles
Browse latest Browse all 3491

Trending Articles