View Full Version : How to set Text for a treenode?

15 Jun 2011, 6:53 PM
hi, I've a problem when I'm trying to set text for a treenode.
I tried to use setText() method, but if the text contains '<a>', there will be an error.
for example :
What should I do to avoid this error? or are there some other ways to set text that contains link for a treenode? thanks!

16 Jun 2011, 5:49 AM
Do you want the tree node to display the literal string "<a>ooo</a>", or do you want it to interpret that as html and display a link? Do you really want a link, or would a 'click' event handler of the node be more appropriate? What do you mean "there will be an error", the results are not what you expect, or that there is actually a javascript error thrown by the page?

I can do setText("<a>ooo</a>") on a TreeNode and it works fine, there is no error thrown. Despite the documentation saying setText sets the text of the node, it actually sets the html of the node so if you set it to "This is <b>bold</b>" you will see some bold text. The <a> do not appear as links because the Ext CSS for tree nodes has turned off the blue underline.

19 Jun 2011, 5:11 PM
I want the tree node to display a link. Using setText() can cause an error in ext-all.js and results are not what I expect. I checked the innerHTML of the tree node. It already has a <a> tag. (I'm using Extjs version 3.2)
I tried to control the innerHTML in this way:
node.ui.getEl().childNodes[0].childNodes[4].innerHTML = "...";
In this way I can set the innerHTML of the tree node and result is correct. But I don't know whether there's some defects. If there's some, please tell me. Thanks!