小程序全选和单选

data() {
        return {
            boundList:[],
            list:[],
            checked:false
            }
        },
// 单选
            isBoundFun(item,index) {
                if(item.isBound) {
                    item.isBound = false
                }else {
                    item.isBound = true
                }
                this.$set(this.list,index,item)
                console.log('单选:',this.list)
            },
            // 全选
            allBtu() {
                var that = this
                if(that.checked){
                    for (var i = 0; i < that.list.length; i++) {
                        that.list[i].isBound = false;
                        that.checked = false
                    }
                }else{
                    for (var i = 0; i < that.list.length; i++) {
                        that.list[i].isBound = true;
                        that.checked = true
                    }
                }
                console.log('全选:',that.list)
            },
this.boundList.forEach((value,index)=>{
    this.list.push(value)
    value["isBound"] = false;    // 新增isBound字段,判断选中还是未选中
})
let params = []
        for(var i=0;i<this.list.length;i++) {
            if(this.list[i].isBound) {
                let par = {
                    searchResultId:this.list[i].id,
                    EquID:this.list[i].EquID,
                    printerCodes:this.list[i].printerCodes
                }
                    params.push(par)
            }
        }    // 传参变成[{},{}]

注:自己瞎写的,没优化代码,需要的自己优化一下,最好别使用for循环哈

posted @ 2021-11-17 17:01  温柔本肉  阅读(87)  评论(0编辑  收藏  举报