Batch delete function of layui table

1      // Batch delete function 
2      // 1. Get the content of the selected row in the table 
3      // 2. Get the unique value required for deletion, usually id; 
4      // 3. Add the item to be deleted to the array; 
5      // 4. Determine whether it is selected; 
6      // 5. Send ajax request with parameter id; 
7       var $=layui.$,active= {
 8           deLink: function () {
 9               var checkStatus=table.checkStatus('idTest' ) ,
 10                   data= checkStatus.data,
 11                   deList= [];
 12               data.forEach( function (n,i){
13                  delList.push(n.id);
14              });
15              if(delList!=''){
16                  layer.comfirm('确定删除所选项吗?',function (index) {
17                      $.ajax({
18                          url: '/cd/workPlatform/tool/remove.afca',
19                          type:'post',
20                          dataType:'json',
21                          data:"id="+delList,
22                          success:function (data,statusText) {
23                              if (data.code==='0' ){
 24                                   layer.msg('Deletion succeeded' );
 25                                   table.reload('idTest' ,{});
 26                               } else {
 27                                   layer.msg('Deletion failed' );
 28                               }
 29                           },
 30                           'error': function () {
 31                               layer.msg('System error' );
32                          }
33                      })
34                   })
 35               } else {
 36                   layer.tips('Please select the row to delete',$('#batchDel' ),{
 37                       tips:[3,'#5fb878' ]
 38                   })
 39               }
 40           }
 41       }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324921793&siteId=291194637