Hi I'm trying to build tree type lists where each row in the list has several cells (columns). My code will render the first list ok then stops. The first 'for' statement should be moving to build the second list, but the loop is killed. The 'list', 'row' and 'cell' constructors are not shown.
Any idea what's killing the initial iteration.. is it the recursion in getChildren()?
Thanks for you help! - function getlist()
-
{
-
this.list = arguments[0].split(",");
-
this.render = function()
-
{
-
document.getElementById('workspace').innerHTML="";
-
for(x in this.list)
-
{
-
var listid = this.list[x];
-
var rootid = list[listid].root;
-
document.getElementById('workspace').innerHTML += list[listid].html;
-
list[listid].resize();
-
resize('workspace', 'list.'+listid);
-
document.getElementById('list.'+listid).innerHTML += row[rootid].html;//render the root's html
-
getcells(rootid, 'row.'+rootid);
-
getChildren(rootid);
-
}
-
}
-
}
-
-
function getChildren(rowid)
-
{
-
for(n in row[rowid].children)
-
{
-
var child = row[rowid].children[n];
-
document.getElementById('children.'+rowid).innerHTML += row[child].html;//add the child row html the the child container
-
getcells(child, 'row.'+child);
-
getChildren(child);//then get the child row's children
-
}
-
}
-
-
function getcells(rowid, target)
-
{
-
for(y in row[rowid].cell)
-
{
-
var cellid = row[rowid].cell[y];
-
document.getElementById(target).innerHTML += cell[cellid].html;//then add the cells to that child row html
-
}
-
}
I've replaced the getChild for ...in loop with a while and it appears to work!
What was the for ..in loop doing wrong? - function getChildren(rowid)
-
{
-
var x = 0;
-
while(row[rowid].children[x])
-
{
-
var child = row[rowid].children[x];
-
document.getElementById('children.'+rowid).innerHTML += row[child].html;//in the rows children container add the child row html
-
getcells(child, 'row.'+child);
-
getChildren(child);//then get the child row's children
-
x=x+1;
-
}
}
10 1920
Hi bugboy,
Use try and catch block for the functions. Then you will know the source of the bug. Or you have to use alert and chek. Moreover in getChildren() you havent used return, since the function is a recursive() it will be expecting a return.
sample Code: - try
-
{
-
//your code goes here.
-
}
-
catch(e)
-
{
-
alert(e.message);
-
}
Thanks and Regards
Ramanan Kalirajan
Is the list variable on line 10 a global? I can't see it declared anywhere.
'list' 'row' and 'cell' are all objects, i haven't shown their constructors.
'getChildren' and 'getCells' both write to the target element in the document so a return isn't needed as far as i know.
If i remove the call to it's self inside getChildren it works fine rendering both lists - except it won't get the children of the children so the tree/list only renders two levels deep. If i leave it in place the first tree/list renders fine with multiple levels but then the second list doesn't render at all, it's as if the initial 'for' loop in getList is just forgotten once recursion starts.
When are you stopping the recursive function?
Thanks and Regards
Ramanan Kalirajan
note: be cautious when using a for … in loop, it does not only fetch the numeric members.
what’s this? (line #26): row[child].html
The recursive function is called inside the for loop so it is only called once for each subchild, when there aren't any subchildren the for loop stops.
Sorry i'm not sure what you mean by not only numeric members.?
(line #26): row[child].html is just an html string being retrieved from the row object.
I've replaced the getChild for ...in loop with a while and it appears to work!
What was the for ..in loop doing wrong? - function getChildren(rowid)
-
{
-
var x = 0;
-
while(row[rowid].children[x])
-
{
-
var child = row[rowid].children[x];
-
document.getElementById('children.'+rowid).innerHTML += row[child].html;//in the rows children container add the child row html
-
getcells(child, 'row.'+child);
-
getChildren(child);//then get the child row's children
-
x=x+1;
-
}
}
@bugboy
numeric members: list[0], list[1], etc. for … in also loops over custom members (anything that is not a numbered member)
Ahh right, Thanks for your help guys!
I'm not sure what the problem was, my arrays only have successive numeric members.. hard to pick the best answer..
Sign in to post your reply or Sign up for a free account.
Similar topics
by: nospam |
last post by:
Reasons for a 3-tier achitecture for the WEB?
(NOTE: I said, WEB, NOT WINDOWS.
DON'T shoot your mouth off if you don't understand the difference.)
I hear only one reason and that's to switch a...
|
by: jabailo |
last post by:
I am looping through a text file, and with each row, I launch a web service,
asynchronously.
Before I move on to the next step in the process, I want to make sure that
all the web services have...
|
by: Richard Cavell |
last post by:
I have a recursive function like this:
void MyFunction(int i)
{
i++;
// do something with i
if (we're not finished) MyFunction(i);
}
I keep count of how far nested we are with i. Now, it...
|
by: F-13 |
last post by:
I'm working on a BOM in Access 200 from an example downloaded from from
the web. The sample database contains three tables, Assemblies (the
list of items needed to assemble any assembly),...
|
by: ryan |
last post by:
Hi,
I've omitted a large chunk of the code for clarity but the loop below is how
I'm calling a delegate function asynchronously. After I start the each call
I'm incrementing a counter and then...
|
by: eb65 |
last post by:
I have a need to write a Windows Service application in VB.Net that
needs to continuously do some processing, wait ten minutes, then
repeat. What is a good approach to coding this type of thing?...
|
by: mturner64 |
last post by:
Good day. I am working on a program that will allow a user to enter an undefined series of numbers and enter -99 when finished. The program should output the Greatest and Least of the series...
|
by: Steve |
last post by:
I am having problems getting values out of an array. The array is set
as a global array and values are pushed into it as they are read from
a JSON file using a "for loop". When the "for loop" is...
|
by: saravanan82 |
last post by:
Hi All,
I tried to execute follwoing program, which got killed by the OS.
#include<stdlib.h>
main()
{
while(1) { char *c=(char*)malloc(10000); }
}
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |