PDA

View Full Version : Tree node and delete entry



pactgmbh
21 Apr 2010, 12:38 AM
Hello Friends,

hot to delete a a tree node entry? I try the API-DOC example. In the docs.js i guess

handler: function(){
var delNode;
var element = this.root.childNodes [0];
},

The result of element is: node apidocs

Any ideas?

Zerogiven
21 Apr 2010, 2:08 AM
hi

first) i think this is totally the wrong board for this question ;)
second) Do you want delete the whole node or just set the text to ''?

ah however here are both solutions:

Delete the whole node:
I hope you know how to get the node you wanna delete, but for example here is a code snippet for the selected node:


var tree = Ext.getCmp("treeId"); // Get the tree by his id
var selectionModel = tree.getSelectionModel(); // Get selection model from the tree
var selectedNode = selectionModel.getSelectedNode(); // Get the selected node

selectedNode.remove();


Set empty text:
just one line is not exact the same than the code above ^^:



var tree = Ext.getCmp("treeId"); // Get the tree by his id
var selectionModel = tree.getSelectionModel(); // Get selection model from the tree
var selectedNode = selectionModel.getSelectedNode(); // Get the selected node

selectedNode.setText("");



i hope that helps you

greetz

pactgmbh
21 Apr 2010, 2:29 AM
That is what I need. Thank you.

gaviles
24 Jan 2011, 9:20 PM
What about removing multiple nodes...

I tried using the remove() function while iterating through an array of selected nodes. It will remove some nodes but not all... I get "TypeError: obj is undefined" (see code below). Any idea of how to remove all of the selected nodes returned in the array from a call to getSelectedNodes()? Appreciate anyone's insight.



var panel = Ext.getCmp('treePanelId');
Ext.each(panel.getSelectionModel().getSelectedNodes(),function(obj){
obj.remove();
});