vant checkBox bulk deletion

There are two ways to achieve, of course, more than two kinds

One: we need to use the filter to filter out, which is not selected to filter which

Two: Use splice array method, we will need to delete the selected index into an array inside, and then delete it. There is a pit splice (splice will change the original array)

 

Let us talk about one:

/ * 
      Suppose we are dependent on the data to be rendered, v-for = "(item , index) in addressList" 
      using the filter, then we can add a key value isDel to each object, you only need to increase a person push { "name": "" , "gender": "", "age": "", "isDel": false}

    
    Each object is added to a key to isDel: to false 
      addressList.forEach ((Item, index) => {
        Item [ "isDel"] = to false
      })

    With the use vantUI inside < Van CheckBox- V-Model = "item.isDel" > </ Van-CheckBox> whenever the check box is selected isDel to true will
   
    last write addressList = item addressList.filter (= > item.isDel === false) This will not filter out selected is equivalent to delete the selected
* / var addressList = [ { "name": "Joe Smith" , "Gender": "M" , "Age ": '22 ' }, { " name ":" John Doe " , " Gender ":" M " , " Age ":' 20 is' }, { " name ":"王五", "gender": "女", "age":'18' }, ]

 

Method Two: Use this method to splice Note that this method will change the original array, a delete is a problem it was, oh, but if you need consecutive deletions will not have pit       https://www.cnblogs.com/ly0612/p/ 6750233.html

    As used herein vant checkBox (box set) The reason for using this mainly to get the selected index  

<CheckBox Van-Model-Group-V = "checkboxResult"> 
     <Van-CheckBox: name = "index"> </ Van-CheckBox> //: name = "index" is selected to obtain an array inside index checkboxResult our store is selected index 
</ Van-the CheckBox-Group>
let newIndexs = this.checkboxResult.map(function(val, idx) {
      return val - idx;
});

newIndexs.forEach((item, index) => {
      this.addingAddressList.splice(item, 1);
});

This is the big brother to tell me how to fill the pit   https://www.cnblogs.com/ly0612/p/6750233.html

 

Guess you like

Origin www.cnblogs.com/TreeCTJ/p/11529875.html