data object question

Y

yeti349

Hi, I have the following data object. Each string in the "lib" element
represents a new record. I need to display each of these records in
html table format so I can be able to sort on each column. How can I
get each string from each element into its own row, or is there a
better way to populate this data object? Thanks.


var jsData = new Array();

for (var i = 0; i < 4; i++)
{
jsData[jsData.length] = {lib: "string1,string2,string3,string4", id:
"num1,num2,num3,num4", com: "string1,string2,string3,string4"};
}

the html table output should look like:

string1 | num1 | string1
string2 | num2 | string2
string3 | num3 | string3
string4 | num4 | string4
 
T

Thomas 'PointedEars' Lahn

var jsData = new Array();

for (var i = 0; i < 4; i++)
{
jsData[jsData.length] = {lib: "string1,string2,string3,string4", id:
"num1,num2,num3,num4", com: "string1,string2,string3,string4"};
}

There is no point in this loop. You should post the original code.
the html table output should look like:

string1 | num1 | string1
string2 | num2 | string2
string3 | num3 | string3
string4 | num4 | string4

Quick hack:

var o = jsData[0];
o.lib = o.lib.split(",");
o.id = o.id.split(",");
o.com = o.com.split(",");

var a = [];
a.push('<table>');
for (var i = 0, len = o.lib.length; i < len; i++)
{
a.push('<tr><td>', o.lib, '<\/td><td>', o.id, '<\/td><td>',
o.com, '<\/td><\/tr>');
}
a.push('<\/table>');

document.write(a.join(""));


PointedEars
 
Y

yeti349

ah yes, that loop was pointless and once i removed it everything seem
to make sense. thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top