[Dojo-interest] calling destroy on templated widget not modifying dom

Nick Fenwick neek at nickfenwick.com
Sun Oct 9 22:42:58 EDT 2016


I'm guessing if you haven't overridden teh destroy() functions and 
forgotten to call this.inherited(arguments) (which I guess you haven't 
because the registry removal etc is working) then I think your problem is:

<div data-dojo-attach-point='domNode'>

The root node of your template should almost always be just '<div>'.  
The 'domNode' reference of a Widget is set up automatically during 
construction.

I would also question:
       postCreate:function(){
         var domNode = this.domNode;
         this.inherited(arguments);
       },

What is the point of this code? You declare a local scope variable 
domNode, never use it, and call the parent class implementation .. 
remove this entire function from your code base.  It's probably not part 
of your problem but it's certainly not a solution to anything.

Nick



On 09/09/16 09:04, derek miller wrote:
> I'm having issues destroying custom, templated widgets... calling 
> widget.destroy() is removing the widget from the registry (and its 
> parent's descendants array, if applicable), but is not removing the 
> widget's dom nodes from the dom.
>
> I'm approaching this under the assumption that widgets inheriting from 
> dijit/_WidgetBase can be removed from the registry and purged from the 
> dom by calling the widget.destroy() method... if that's not the case 
> -- you can correct me right here :)
>
> I've had this issue for some time, and have been hacking it ... would 
> like to know what I'm doing wrong.
>
> Simple example --
>
> widget template
>
> <div data-dojo-attach-point='domNode'>
>   <div data-dojo-attach-point='left'></div>
>   <div data-dojo-attach-point='center'>${cName}</div>
>   <div data-dojo-attach-point='right'></div>
> </div>
>
> widget code
>
> define([
>   "dojo/_base/declare",
>   "dijit/_WidgetBase",
>   "dijit/_TemplatedMixin",
>   "dojo/text!./templates/dCard.html"
>   ],
>   function (declare, _WidgetBase, _TemplatedMixin, template){
>     return declare([_WidgetBase, _TemplatedMixin],{
>       templateString:template,
>       postCreate:function(){
>         var domNode = this.domNode;
>         this.inherited(arguments);
>       },
>     });
>   }
> );
>
> let's assume that there's a dojox/mobile/ContentPane in the dom, var'd 
> out as rBox
>
> >> window.rBox = new ContentPane({id:'rBox'}).placeAt(document.body);
>
> iterate over an array of data and create widgets
>
> >> var data = {"records":[{"cname":"Gary Kunz"},{"cname":"Bigham, 
> Michael},{"cname":"Westlund, Michael"}]};
>
> >> data.records.forEach(function(x){
>       rBox.addChild(new simpleWidget({cName:x.cname}));
>     });
>
> Still with me? Now - I can call rBox.destroyDescendants(); .... 
> rBox.getChildren().forEach(function(child){child.destroy();}); .... I 
> can get explicit references to the widget and call destroy on it 
> directly...
>
> I get the same result. The widget(s) are removed from the registry (or 
> the parent's child array), but the widget's dom representation is 
> staring me in the face....
>
> I have got to be missing something... anybody have any ideas?
>
> Thanks all. Much appreciated.
>
> - derek
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.dojotoolkit.org/pipermail/dojo-interest/attachments/20161010/b02dac15/attachment.htm 


More information about the Dojo-interest mailing list