473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Keep track of parent node

In javascript a tree structure node i have a subnode and it has
parentnode and that parentnode has one parent how do i get all parent
node when i click the subnode

Jan 31 '06 #1
5 3793

rm**********@gmail.com wrote:
In javascript a tree structure node i have a subnode and it has
parentnode and that parentnode has one parent how do i get all parent
node when i click the subnode


var arrayParents = new Array;
if (child.parent) {
var currentParent = child.parent;
arrayParents.push(currentParent);
while(currentParent.parent) {
currentParent = currentParent.parent;
arrayParents.push(currentParent);
}
}

and there you have the array of parents. Adapt this algorithm to your
tree and code

Jan 31 '06 #2
Thanks a lot

Feb 1 '06 #3
impaler wrote:
rm**********@gmail.com wrote:
In javascript a tree structure node i have a subnode and it has
parentnode and that parentnode has one parent how do i get all parent
node when i click the subnode

var arrayParents = new Array;
if (child.parent) {
var currentParent = child.parent;
arrayParents.push(currentParent);
while(currentParent.parent) {
currentParent = currentParent.parent;
arrayParents.push(currentParent);
}
}


More concisely:

function getParentArray(el)
{
var parent, parentArray = [];
while((el = el.parentNode)){
parentArray.push(el);
}
return parentArray;
}


--
Rob
Feb 1 '06 #4
RobG wrote:
[...]

function getParentArray(el)
{
var parent, parentArray = [];
Aggh...

var parentArray = [];

while((el = el.parentNode)){
parentArray.push(el);
}
return parentArray;
}

--
Rob
Feb 1 '06 #5
RobG wrote:
RobG wrote:
[...]
function getParentArray(el)
{
var parent, parentArray = [];


Aggh...

var parentArray = [];


That is equivalent :)
Regards,
PointedEars
Feb 15 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: dannielum | last post by:
Hi all, I am trying to write a Binary Search Tree that each of its node will have 3 node pointers: left, right and parent. I need a parent pointer for some the purpose of my project. Without the...
1
by: clintonG | last post by:
How do I get a TreeNode.Parent property when using the 2.0 TreeView control? When the data source is an XML file there may be redundant names in the tree. For example, when a child node with the...
7
by: amruta | last post by:
the code below dows not let me get the parent child view... all the nodes are show in one line only... also i need them to be collasped ... Thanks ..
6
by: SQACSharp | last post by:
I'm using the EnumChildWindows API with an EnumChildWndProc callback to populate the treeview. The output will be something similar to spy+ + How can I specify the parent when adding a new node...
0
by: Guzeppi | last post by:
Hi, i'm using linq to load an xml structure into my classes. the xml consists of the same node nested for multiple levels e.g. <node id="node_id01" name="node 01"> <node id="node_id0101"...
1
by: bnchs | last post by:
This is C code. I am trying to fill each node's Parent field with its parent because I am drawing nodes to the screen. However, I have not been able to get this working. Reading the output from the...
1
by: Author | last post by:
I have an xml document that looks *like* so: <Mammal name="Cat"> <Mammal name="African Tigers" > <Mammal name="Central African Tiger" /> <Mammal name="Ethiopian Tiger" /> </Mammal> <Mammal...
1
by: SWETA123 | last post by:
I will very helpful to you if you can help me out in my below problem. I am not getting idea what should be the right approach for this. Here is my problem. I have below (sample)xml. <Rules>...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.