Sort JSON array objects-the same elements with the same key, the number of groups is inconsistent, you can use the following JS to loop the table output

Source: Internet
Author: User

                varnow=eval (data.data);//Now.sort (sortby (' Bigidorder ', True, parseint));                varTab= ""; varK=0; varHangye=0; varindex = 0;//alert (json.stringify (now[i));                     for(vari=0;i<now.length;i++) {Index++; if(now[i].bigid!=Hangye) {                                if(i==0){//the beginning of the first tabletab + = ' <table id= ' tab ' +k+ ' > '; tab+ = ' <tr><th> Industries </th><th> brands </th><th> frequency (Times) </th><th> duration (seconds) </th ></tr> '; }                                Else{                                     for(j=5;j>=index;j--) {tab+ = "<tr>"; tab+ = "<td >--</td>"; tab+ = "<td >--</td>"; tab+ = "<td >--</td>"; tab+ = "<td >--</td>"; tab+ = "</tr>"; }//End of previous table//the beginning of the next tabletab + = ' </table> '; tab+ = ' <table id= ' tab ' +k+ ' > '; tab+ = ' <tr><th> Industries </th><th> brands </th><th> frequency (Times) </th><th> duration (seconds) </th ></tr> '; Index= 1; } Hangye=Now[i].bigid; }//row of the current table                            //Hangye = Now[i].bigid                            if(index<6) {tab+ = "<tr>"; tab+ = "&LT;TD >" +now[i].bigindustryname+ "</td>"; tab+ = "&LT;TD >" +now[i].brandname+ "</td>"; tab+ = "&LT;TD >" +now[i].pinci+ "</td>"; tab+ = "&LT;TD >" + (now[i].timesize*1). toFixed (2) + "</td>"; tab+ = "</tr>"; }                    }                                         for(j=5;j>index;j--) {tab+ = "<tr>"; tab+ = "<td >--</td>"; tab+ = "<td >--</td>"; tab+ = "<td >--</td>"; tab+ = "<td >--</td>"; tab+ = "</tr>"; } tab+ = "</table>"; //                }$ (". Industrybrandtrendsubtab"). html (tab);

Sort JSON array objects-the same elements with the same key, the number of groups is inconsistent, you can use the following JS to loop the table output

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.