<template>
<view>
<button @click="change_value">更换</button>
<checkbox-group @change="checkboxChange">
<view v-for="(item,index) in records" :key="index">
{{item.checked}}
<checkbox :value="String(item.id)" :checked="Boolean(item.checked)" />
</view>
</checkbox-group>
</view>
</template>
<script>
export default {
name: "",
data() {
return {
records:[{checked:false,id:1},{checked:false,id:2},{checked:false,id:3},{checked:false,id:4},{checked:false,id:5}],
sure:[]
}
},
methods:{
change_value(){
this.records=this.sure
},
checkboxChange(e){
var values = e.detail.value
var records=this.records
var sure=this.sure
console.log(values)
records.forEach((k,j)=>{
if(values.indexOf(String(k.id))!=-1){
records[j].checked=true
let flag=0
sure.forEach((k2,j2)=>{
if(k2.id==k.id){
flag=1
}
})
if(flag==0){
sure.push(k)
}
console.log(sure)
}else{
records[j].checked=false
sure.forEach((k2,j2)=>{
if(values.indexOf(String(k2.id))==-1){
sure.splice(j2,1)
}
})
}
})
console.log(sure)
this.sure=sure
this.records=records
}
}
}
</script>
<style lang="scss" scoped>
</style>
0 个回复