使用javascript从表格制作树图

时间:2015-03-17 10:32:24

标签: javascript arrays loops

下表有3列,我想制作一个树形图(不需要用图形表示。可以用表格表示。)

FIELD1包含唯一ID,ref ID包含引用ID。我想用FIELD1映射ref id,然后再次获取映射引用id的FIELD1 id,然后继续执行直到层次结束。

例如。如果我得到FIELD1的第一行数据(1),那么我想从name1列获取名称,其中num 1在ref id中。然后那些ref id我应该再次映射FIELD1 ID。

Eg: 1----> A1 its FIELD1 = 1
           Andy its FIELD1 = 12
           Billy Jo its FIELD1 = 25

然后我必须再次获得12并在ref id列中搜索它。这是我应该做的方法。我只能使用javascript。

//FIELD1    name1   ref ID    
//1 Al  1    
//2 Alan    7    
//3 Alan    21    
//4 Alan    0   
//5 Alex    4    
//6 Alfredo 4    
//7 Alvin   18    
//8 Andre   20    
//9 Andre   17    
//10    Andres  10    
//11    Andres  6    
//12    Andy    1    
//13    Andy    13    //
//14    Argenis 0    
//15    Barry   16    
//16    Ben 5    
//17    Bill    7    
//18    Bill    18    
//19    Bill    6    
//20    Bill    10    
//21    Bill    0    
//22    Bill    7    
//23    Billy   3    
//24    Billy   6    
//25     Billy Jo   1    
//26    Billy   6    
//27    Bip 1    
//28    Bo  10    
//29    Bob 1    
//30    Bob 16    
//31    Bob 4    
//32    Bob 27    
//33    Bob 6    
//34    Bob 5    
//35    Bobby   3    
//36    Bobby   9    
//37    Bobby   0    
//38    Brett   4    
//39    Brian   20    
//40    Brook   17    
//41    Bruce   6    
//42    Bruce   8    
//43    Buddy   20    
//44    Buddy   2    
//45    Butch   7    
//46    Cal 25    
//47    Candy   18   
//48    Carlton 14    
//49    Carmelo 9    
//50    Carmen  8    
//51    Carney  19    
//52    Cecil   12    
//53    Charlie 3    
//54    Chet    12    
//55    Chili   13    
//56    Chris   2    
//57    Chris   7    
//58    Chris   6    
//59    Cliff   0    
//60    Cory    24    
//61    Craig   6    
//62    Curt    2    
//63    Curt    0    
//64    Dale    29    
//65    Dale    7    
//66    Damaso  6    
//67    Dan 4    
//68    Dan 16    
//69    Dann    4    
//70    Danny   5    
//71    Danny   25    
//72    Darnell 20    
//73    Darrell 29    
//74    Darrell 12    
//75    Darren  8    
//76    Darryl  7    
//77    Darryl  27    
//78    Daryl   5    
//79    Dave    1    
//80    Dave    1    
//81    Dave    3    
//82    Dave    15    
//83    Dave    35    
//84    Dave    31    
//85    Dave    24    
//86    Davey   7    
//87    Denny   13    
//88    Dick    13    
//89    Dickie  3    
//90    Don 31    
//91    Don 31    
//92    Don 13    
//93    Donnie  4    
//94    Doug    0    //
//95    Doug    26    
//96    Dwayne  9    
//97    Dwight  26    
//98    Ed  2    
//99    Eddie   15    
//100   Eddie   17    
//101   Enos    2    
//102   Eric    27    
//103   Ernest  9    
//104   Ernie   16    
//105   Floyd   8    
//106   Frank   22    
//107    Franklin   23    
//108   Fred    23    
//109   Garry   2    
//110   Garth   3    
//111   Gary    24    
//112   Gary    34    
//113   Gary    21    
//114   Gary    5    
//115   Gary    11    
//116   Gary    5    
//117   George  31    
//118   George  16    
//119   George  14    
//120   George  14    
//121   Glenn   4    
//122   Glenn   31    
//123   Glenn   4    
//124   Glenn   15    
//125   Gorman  16    
//126   Graig   16    
//127   Greg    16    
//128   Greg    12    
//129   Greg    13    
//130   Hal 7    
//131   Harold  21    
//132   Harold  1    
//133   Harry   5    
//134   Herm    4    
//135   Howard  10    
//136   Hubie   14    
//137   Jack    9    
//138   Jack    4    
//139   Jamie   8    
//140   Jeff    2    
//141   Jeff    6    
//142   Jeffrey 6    
//143   Jerry   5    
//144   Jerry   5    
//145   Jerry   5    
//146   Jerry   4    //
//147   Jesse   40    //
//148   Jim 8    
//149   Jim 7   
//150   Jim 23

0 个答案:

没有答案