JS实现全选,取消全选,正常选择

本文详细介绍了在Vue框架中实现全选与取消全选功能的具体代码逻辑,包括如何更新用户ID列表、昵称显示及选择状态。通过遍历选项并根据条件更新界面显示,确保了用户体验的流畅性和准确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//点击选择方法
onUserIdsChange(selVal) {
if (this.form.groupUserIds.includes(-1) && !this.isSelectAll) {
// 全选
this.nickNames = []
this.isSelectAll = true
this.form.groupUserIds = []
this.groupUserOption.forEach(item => {
item.value != -1 && this.form.groupUserIds.push(item.value)
if(this.form.groupUserIds.length !== 0 && item.subscribe !== true){
this.onShow = true
this.nickNames.push(item.label)
}
})
this.groupUserOption[0].label = '取消全选'

    } else if (this.isSelectAll && this.form.groupUserIds.includes(-1)) {
     **// 取消全选**
      this.isSelectAll = false
      this.groupUserOption[0].label = '全选'
      this.form.groupUserIds = []
      this.onShow = false
      this.nickNames = []
    } else {
      **// 正常选择**
      this.nickNames = []
      this.form.groupUserIds = selVal
      if(this.form.groupUserIds.length === this.groupUserOption.length - 1){
        this.groupUserOption[0].label = '取消全选'
      }else{
        this.groupUserOption[0].label = '全选'
      }
      if(this.form.groupUserIds.length !== 0){
       this.groupUserOption.forEach(item2 => {
         this.form.groupUserIds.forEach(item => {
           if(item2.value === item && item2.subscribe !== true){
            this.onShow = true
            this.nickNames.push(item2.label)
          }else if(item2.value === item && item2.subscribe === true){
            this.onShow = false
          }
         })
       })
      }
      else{
        this.onShow = false
        this.nickNames = []
      }
    }
  }
},

转载于:https://www.cnblogs.com/zppsakura/p/11376780.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值