Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

    checked(e, index) {
      //e:当前状态false或true
      //index:当前索引

      //方法一:a为数组
      if (e) {
        //选中,就把b数组对应当前索引的数据赋给a数组
        this.a[index] = this.b[index]; 
      } else {
        //取消,就把a对应的数组位置设为空
        this.a[index] = undefined; 
      }
      //...最后整理出a数组里不为undefined的数据返回


      //方法二:a为对象
      if (e) {
        //选中,就把b数组对应当前索引的数据赋给a对象
        this.a[this.b[index].uid] = this.b[index]; 
      } else {
        //取消,直接删除对象属性
        delete this.a[this.b[index].uid]; 
      }
      //把对象数据整理成数组返回
    },

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.5k views
Welcome To Ask or Share your Answers For Others

1 Answer

可以考虑直接挂载到this.b数组

checked(e, index) {
      this.b[index].checked = e;
      return this.b.filter(({ checked }) => checked);
},

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...