JS code to achieve the shopping cart effect

Source: Internet
Author: User

The page is divided into two parts, the upper part is all the data, the next part is the shopping cart. By selecting the data to be processed on the above to add into the shopping cart, to achieve the unified processing of shopping cart data.

Note that there are two points: ① shopping cart data can be deleted, and can not be repeated add ② response time considerations, shopping cart single processing data limit to 200

The code is as follows:

/** * Add into cart method*/functionAddtodowngrid () {varSelrows = $ ("#basicInfoList"). DataGrid ("getchecked");//the selected user area    if(selrows==NULL|| Selrows.length==0) {$.messager.alert (' Prompt ', ' no user info selected! ', ' info '); return; }    //Add the following list    varCurrows = $ ("#ywCustomerGrid"). DataGrid ("GetRows");//user area added to Cart        //Check whether the number of shopping carts exceeds the upper limit after this addition    varMaxSize = 200; if(Selrows.length + currows.length >maxSize) {$.messager.alert (' Hint: ', ' shopping cart remaining can add ' + (maxsize-currows.length) + ' data, this time check ' +selrows.length+ ' bar, add failed! ', ' info '); return; }         var map = {}; $.each (currows,  function(index, Currow) {map[currow.id] = currow.id; }) //check duplicates, sift through duplicate selected data     for(vari = 0; i<selrows.length; i++){         var target = map[selrows[i].id]; if(target) {$.messager.alert ("Prompt", "Shopping cart already exists user code:" + Selrows[i].code + "Information!! "," info "); return ; }} $.each (Selrows,function(index, Selrow) {$ ("#ywCustomerGrid"). DataGrid ("Appendrow"), Selrow); }) $.messager.alert (' Hint: ', ' added successfully! ', ' info '); //Clear on List selection$ ("#basicInfoList"). DataGrid ("Uncheckall"));}/** * Move out of shopping cart method*/functionRemovefromdowngrid () {varCustomerrow = $ ("#ywCustomerGrid"). DataGrid ("GetSelected"); if(!Customerrow) {$.messager.alert (' Prompt: ', ' no user selected! ', ' info '); return false; }  varSelrows = $ ("#ywCustomerGrid"). DataGrid ("GetChecked"); if(selrows!=NULL&& selrows.length>0){     for(vari=0;i<selrows.length;i++){        varRowIndex = $ ("#ywCustomerGrid"). DataGrid ("Getrowindex", Selrows[i]); $("#ywCustomerGrid"). DataGrid ("DeleteRow"), RowIndex); }  }  //Empty Shopping Cart selection$ ("#ywCustomerGrid"). DataGrid ("Uncheckall"));}

JS code to achieve the shopping cart effect

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.