Tuesday, June 11, 2013

Destroy a controller's HTML by id in a dojox/app application.

If you are transitioning leftward in a breadcrumb trail and you want to throw away the thing you are pulling back from, you may need to delay doing so until after the transition has run its course (least you sabotage the transition, DOM, and user experience) like so:

function destroyDomNode(view) {
   require(["dojo/request"],
      function(request) {
         request("index.html").then(
            function(){
               setTimeout(function() {
                  require(["dojo/dom-construct"], function(domConstruct){
                     domConstruct.destroy(view);
                  });
               }, 1000);
            }
         );
      });
}

 
 

This assumes index.html is always going to be there. You can also bolt on a fail function. It would sit just after the third to last closing curly bracket and look like so (perhaps):

, function(error){ alert(error); }

 
 

The unneeded call to index.html is a hack. I need to find a better way. (more soon, I hope) This posting assumes Dojo 1.9.

No comments:

Post a Comment