javascript - Multiple values of same JSON Tag -
i have 1 json object coming html transferring javascript function defined below. problem getting same foldername listed in repition on html page.
json object:
{ "foldername": "arjunram-test", "objects": [ { "keyname": "shadowbalancemismatch_april.csv", "keyvalue": "shadowbalancemismatch_april.csv" }, { "keyname": "rawlogs.txt", "keyvalue": "rawlogs.txt" }, { "keyname": "expiredpoints.txt", "keyvalue": "expiredpoints.txt" } ], "childdirs": [ { "foldername": "20140601.csv", "objects": [ { "keyname": "expiredpoints.txt", "keyvalue": "20140601.csv/expiredpoints.txt" } ], "childdirs": [ { "foldername": "20140601-test", "objects": [ { "keyname": "customerid.txt", "keyvalue": "20140601.csv/20140601-test/customerid.txt" } ], "childdirs": [] }, { "foldername": "test-folder", "objects": [ { "keyname": "amazon_points_proposal20110421_final.docx", "keyvalue": "20140601.csv/test-folder/amazon_points_proposal20110421_final.docx" } ], "childdirs": [] } ] }, { "foldername": "20140602.csv", "objects": [ { "keyname": "[songs.pk] 01 - ek villain - galliyan.mp3", "keyvalue": "20140602.csv/[songs.pk] 01 - ek villain - galliyan.mp3" }, { "keyname": "screen1.jpg", "keyvalue": "20140602.csv/screen1.jpg" }, { "keyname": "[songs.pk] 05 - ek villain - hamdard.mp3", "keyvalue": "20140602.csv/[songs.pk] 05 - ek villain - hamdard.mp3" }, { "keyname": "[songs.pk] 06 - ek villain - galliyan (unplugged).mp3", "keyvalue": "20140602.csv/[songs.pk] 06 - ek villain - galliyan (unplugged).mp3" }, { "keyname": "[songs.pk] 04 - ek villain - awari.mp3", "keyvalue": "20140602.csv/[songs.pk] 04 - ek villain - awari.mp3" }, { "keyname": "2.jpg", "keyvalue": "20140602.csv/2.jpg" }, { "keyname": "4-2.jpg", "keyvalue": "20140602.csv/4-2.jpg" }, { "keyname": "3.jpg", "keyvalue": "20140602.csv/3.jpg" }, { "keyname": "0.jpg", "keyvalue": "20140602.csv/0.jpg" }, { "keyname": "form 2 guide.pdf", "keyvalue": "20140602.csv/form 2 guide.pdf" }, { "keyname": "screen3.jpg", "keyvalue": "20140602.csv/screen3.jpg" }, { "keyname": "4-0-3.jpg", "keyvalue": "20140602.csv/4-0-3.jpg" }, { "keyname": "4-1-3.jpg", "keyvalue": "20140602.csv/4-1-3.jpg" }, { "keyname": "4-1-1.jpg", "keyvalue": "20140602.csv/4-1-1.jpg" }, { "keyname": "[songs.pk] 02 - ek villain - banjaara.mp3", "keyvalue": "20140602.csv/[songs.pk] 02 - ek villain - banjaara.mp3" }, { "keyname": "4-1.jpg", "keyvalue": "20140602.csv/4-1.jpg" }, { "keyname": "4-0-2.jpg", "keyvalue": "20140602.csv/4-0-2.jpg" }, { "keyname": "4-0-1.jpg", "keyvalue": "20140602.csv/4-0-1.jpg" }, { "keyname": "1.jpg", "keyvalue": "20140602.csv/1.jpg" }, { "keyname": "screen2.jpg", "keyvalue": "20140602.csv/screen2.jpg" }, { "keyname": "base.jpg", "keyvalue": "20140602.csv/base.jpg" }, { "keyname": "[songs.pk] 03 - ek villain - zaroorat.mp3", "keyvalue": "20140602.csv/[songs.pk] 03 - ek villain - zaroorat.mp3" }, { "keyname": "4-pending.jpg", "keyvalue": "20140602.csv/4-pending.jpg" }, { "keyname": "4-3.jpg", "keyvalue": "20140602.csv/4-3.jpg" }, { "keyname": "all.jpg", "keyvalue": "20140602.csv/all.jpg" }, { "keyname": "screen4.jpg", "keyvalue": "20140602.csv/screen4.jpg" }, { "keyname": "4-1-2.jpg", "keyvalue": "20140602.csv/4-1-2.jpg" } ], "childdirs": [ { "foldername": "testing-paging", "objects": [ { "keyname": "0.jpg", "keyvalue": "20140602.csv/testing-paging/0.jpg" }, { "keyname": "4-pending.jpg", "keyvalue": "20140602.csv/testing-paging/4-pending.jpg" }, { "keyname": "4-1.jpg", "keyvalue": "20140602.csv/testing-paging/4-1.jpg" }, { "keyname": "4-3.jpg", "keyvalue": "20140602.csv/testing-paging/4-3.jpg" }, { "keyname": "4-0-3.jpg", "keyvalue": "20140602.csv/testing-paging/4-0-3.jpg" }, { "keyname": "4-0-2.jpg", "keyvalue": "20140602.csv/testing-paging/4-0-2.jpg" }, { "keyname": "4-0-1.jpg", "keyvalue": "20140602.csv/testing-paging/4-0-1.jpg" }, { "keyname": "1.jpg", "keyvalue": "20140602.csv/testing-paging/1.jpg" }, { "keyname": "4-1-3.jpg", "keyvalue": "20140602.csv/testing-paging/4-1-3.jpg" }, { "keyname": "4-1-1.jpg", "keyvalue": "20140602.csv/testing-paging/4-1-1.jpg" }, { "keyname": "2.jpg", "keyvalue": "20140602.csv/testing-paging/2.jpg" }, { "keyname": "4-2.jpg", "keyvalue": "20140602.csv/testing-paging/4-2.jpg" }, { "keyname": "3.jpg", "keyvalue": "20140602.csv/testing-paging/3.jpg" }, { "keyname": "4-1-2.jpg", "keyvalue": "20140602.csv/testing-paging/4-1-2.jpg" } ], "childdirs": [] } ] }, { "foldername": "test-repet", "objects": [ { "keyname": "4-pending.jpg", "keyvalue": "test-repet/4-pending.jpg" } ], "childdirs": [] } ] }
html:
<div class="panel accordion clearfix" id="dispdir"> <script type="text/javascript"> window.onload = function() { showdirectorysegment(${s3directorylist},"folder",null); <!-- ${s3directorylist} contains json object defined above }; </script> </div>
javascript:
function showfolders( folderlist ) { console.log(folderlist.length); var markup = ""; ( var = 0; < folderlist.length; i++ ) { var fid = "folder_"+folderid; markup += "<div class=\"well clearfix\" style=\"background-color:#ffe88d;font-size:15px\">"; markup += "<a style=\"text-decoration:none\" id='" + fid + "'><i class=\"fa fa-folder\"></i> " + folderlist[i].foldername + "</a></div>"; $("#dispdir").append(markup); $("#" + fid).on("click", (function(i){ return function(){ showdirectorysegment(folderlist[i],"folder", fid); }; })(i) ); folderid += 1; } } function showdirectorysegment( dirlist, target, elemid ) { var markup = ""; var pid; markup += "<div class=\"clearfix\">"; markup += showobjects(dirlist.objects) + "<br><br>"; document.getelementbyid("dispdir").innerhtml = markup; showfolders(dirlist.childdirs); $("#dispdir").append("</div>"); if ( target == "folder" ) { pid = "path_" + pathid; var pmarkup = "<a style=\"text-decoration:none\" id='" + pid + "'>" + dirlist.foldername + " /</a>"; $("#dirpath").append( pmarkup ); $("#" + pid).on("click",function(){ showdirectorysegment(dirlist, "path", pid); }); pathid += 1; } else if ( target == "path" ) { $("#"+elemid).nextall().remove(); } }
this silly mistake every programmer bound , has right it. there need remove '+' sign first markup statement inside loop in getfolders function
Comments
Post a Comment