uni-app 實現列表數據選中多個功能


<view :class="['list',{'selected':groupIds.includes(item.ssTid)}]"  v-for="(item, index) of list.data" :key="index" @click="handleToSelect(item.ssTid)">
  <view class="ev"><view>商品名稱:</view><view>{{ item.sgName || '-' }}</view></view>
</view>

 

// 選中的樣式

.selected{

  border:2px solid red;

}

 

<script>

  data() {

    return: {

      groupIds: []  // 選中的數據數組

    }

  }

</script>

 

// 點擊選擇
handleToSelect(id){
  let _this = this;
  let arr = _this.groupIds;
  if(arr.includes(id)){
    //includes()方法判斷是否包含某一元素,返回true或false表示是否包含元素,對NaN一樣有效
    let index = arr.indexOf(id); // 判斷數組中是否有選中的id,如果有則去掉
    if(index > -1){
      arr.splice(index,1)
    }
  }else{
    _this.groupIds.push(id)
  }
},


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM