选中取消push和splice删除

data:{
arry:[
    {
      id:1,
      name:'dada'
    },
    {
      id:2,
      name:'aaa'
    }
  ]
}
 fanxuan(){
    let that = this
    let arry = that.data.arry
    let id = '4'//当前选中的id
    let aaa = {
      id:3,
      name:'woshi3'
    }//当前选中的对象
    for(let i in arry){
      if(arry[i].id == id){//判断当前push的有没有重复的,有就反选
        arry.splice(i,1)
        console.log(arry)
        return false
      }
    }
    arry.push(aaa)
    console.log(arry)
  },

你可能感兴趣的:(微信小程序)