How JavaScript handles a lot of data, such as paging switch

Source: Internet
Author: User

Requirements: A user list data, if the corresponding list of data is greater than 10, every 10 saved to a two-dimensional array, less than 10 are still placed in the tail of the two-dimensional array

Useful: analog paging, or partial refresh

varobj=[        {            "List": [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}, {a:7},{a:8},{a:9}            ]        },        {            "List": [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}, {a:7},{a:8},{a:9},{a:10},{a:11},{a:12}, {a:13},{a:14},{a:15},{a:16},{a:17}, {a:18},{a:19},{a:20},{a:21}            ]        },        {            "List": [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}, {a:7},{a:8},{a:9},{a:10},{a:11},{a:12}, {a:13},{a:14},{a:15},{a:16},{a:17}, {a:18},{a:19},{a:20},{a:21},{a:22}, {a:23},{a:24},{a:25},{a:26},{a:27}, {a:28},{a:29},{a:30},{a:31}            ]        },        {            "List": [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}, {a:7},{a:8},{a:9},{a:10},{a:11},{a:12}, {a:13},{a:14},{a:15},{a:16},{a:17}, {a:18},{a:19},{a:20},{a:21},{a:22}, {a:23},{a:24},{a:25}            ]        },        {            "List": [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}, {a:7},{a:8},{a:9},{a:10},{a:11},{a:12}, {a:13},{a:14},{a:15},{a:16},{a:17}, {a:18},{a:19},{a:20},{a:21},{a:22}, {a:23},{a:24},{a:25}            ]        }    ]; //Each list may have a length of 0, no limit    //if the corresponding list.length>10, put the corresponding list every 10 in a two-dimensional array, less than 10 in the tail of the two-dimensional array,    //For example, the third one has 31, and the third list is replaced by:    //  [    //[{a:1},{a:2}: {a:10}],    //[{a:11},{a:12} ... {a:20}],    //[{a:21}: {30}],[{a:31}]    //  ]    //    //How do I get all the two-dimensional arrays at once?     functionresetdate (arr,num) {//1 length of entire array        varleng=arr.length;  for(vari=0;i<leng;i++){            //2 each list            varinnerlist=arr[i].list; //Console.log (arr);            //3 Number of each list, i.e. Lenth            varInnerlength=innerlist.length; //if more than 10            if(innerlength!=0&&innerlength>num) {                //if the length of the outer array of the two-dimensional array is greater than 10: max, you need to take the entire                varOutermaxlen=math.ceil (Innerlength/num);//defines the outer layer of a two-dimensional array on each object                //Arr[i].outer=array (Outermaxlen);Arr[i].outer=[]; varSlicenum = 0, Resindex = 0; //Console.log (Result)                 while(Slicenum <innerlength) {Arr[i].outer[resindex+ +] = Innerlist.slice (slicenum, slicenum + =num); }                //need to use Arr.slice (start,end);Console.log (Arr[i].outer); }}} resetdate (obj,10);//law two,, less than 10 a little bit of a bug (said not to understand), from: The BA GodfunctionAdapter (data) {function_splice (list,i) {i= I | | 1; List.push (List.splice (0,10)); List.length>10? _splice (list,++i): List.push (List.splice (0,list.length-i)); } Data.foreach (function(v) {_splice (v.list); });} Adapter (obj); Console.log (obj);

How JavaScript handles a lot of data, like a paging switch

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.