#1444 closed defect (worksforme)
when destroying the children, the tree.children.length keep increasing
Reported by: | Owned by: | ilia | |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | Widgets | Version: | 0.3 |
Keywords: | tree | Cc: | |
Blocked By: | Blocking: |
Description
I've created a tree widget that has new content as the user click on the server. the parent (always the same) will have 4 children always: Host, CPU, NIC, Partition. However, the grandchildren will always be different.
When I destroy the children, I assume that it has 4 children. However, when I debug this, the tree.children.length always increases by multiple of 4. Is this an expected behavior. I used DOJO 0.3.1. if I just use a fixed length (4), the tree children doesn't get destroy and I will get duplicate.
Here is the snippet of code:
.. pane = dojo.widget.byId("pane1"); tree = dojo.widget.manager.getWidgetsByType("Tree")[1]; dojo.debug("Number of children:"+tree.children.length); for(i=0;i<tree.children.length;i++) {
tree.children[i].destroy();
} .. .. inode = dojo.widget.createWidget("TreeNode?", {title: "Host"}); tree.addChild(inode); cnode = dojo.widget.createWidget("TreeNode?", {title: "Hostname:"+host.name}); inode.addChild(cnode); .. .. inode = dojo.widget.createWidget("TreeNode?", {title: "CPU"}); tree.addChild(inode); .. .. inode = dojo.widget.createWidget("TreeNode?", {title: "NIC"}); tree.addChild(inode); .. ..
Change History (4)
comment:1 Changed 16 years ago by
Milestone: | → 0.5 |
---|
comment:2 Changed 16 years ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:3 Changed 16 years ago by
Milestone: | 0.5 → 0.4 |
---|
Johnny, try going through the index in reverse order... once you delete an item, the length of the array decreases... also, be sure you use var for i to keep in the local scope:
for(var i=tree.children.length-1;i>-1;i--)