let´s assume i have a widget area on my webapp
- <div id="widgetbox">
- // my widget goes in here
- </div>
then i start a new controller for it, to make this thing happen
- 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:
- $('#widgetbox').remove();
But then my widget area is gone. where to append the new controller? So i tried different approches
- weatherWidget.destroy() // destroys all bindings, nice! but the html is still there
- weatherWidget.element.html("") // dont work, because destroy deleted the element/whole control object
another option
- weatherWidget.element.html("") // kills html, but events still there
- 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.
- weatherWidget.destroy() // destroys all bindings, nice! but the html is still there
- $('#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?