How to get parentNode's id and text,untile root

click one node, how to get parentNode’s id and text,untile root
for example
a
b
c
d
when click node d,return d/c/b/a`4/3/2/1.
d/c/b/a is the text,
4/3/2/1 is id

and how to get parentNode’s id and text,untile second level root
for example
a
b
c
d
when click node d,return d/c/b`4/3/2.

d/c/b is the text
4/3/2 is id

I solved the problem