首先描述一下问题吧,最近在开发中遇到一个问题,就是想要提取带有多选框table中的id,然后将所选中表中的key值为id(任务号)的数据以数组的形式传给后端,

HTML部分:

<el-button type="primary" size="medium" @click="speedupCheckbox"><i class="el-icon-time"> 全速</i></el-button>


<el-table :data="tableData5" ref="multipleTable" style="width: 100%;margin-left: 10px;"
            @selection-change="handleSelectionChange">
    <el-table-column type="selection" width="35" v-model="multipleSelection"></el-table-column>
    ......................................................
    .....................................................
    .....................................................
    .....................................................
    <el-table-column label="任务号" prop="id" sortable></el-table-column>

</el-table>
data()部分:

data(){
    return{
        formInline: {
            id: null,
            scene: '',
            project_name: '',
            submit_date: [new Date(),new Date()] ,

        },
        tableData5[],
        multipleSelection[],
    }
}

methods部分:
methods:{
    handleSelectionChange(val) {
    this.multipleSelection = val;
    },
    //全速
    speedupData(){
        var arr=this.multipleSelection;
        let multis = [];
        for (var i=0;i<arr.length;i++){
        multis.push(arr[i].id);
        console.log(multis)
    }
//以上为将数组中key值为id的数据遍历出来,然后,将所得到的数据传入mutis数组中,最后将multis数据提交至后端
     var url = this.HOST + "/job";
     this.$axios.post(url,{
        operate:'speedup',
        job_ids:multis
        }).then(rs=>{
            if(multis.length!==null){
                this.$message.success("操作成功")
            }else{
                this.$message.error("操作失败")
            }
            console.log(rs);
            })
        this.$refs.multipleTable.clearSelection();            //操作完成清除勾选框
        },
//全速选择框
    speedupCheckbox() {
        if (this.multipleSelection.length === 0) {
            this.$message({
                message: '请至少勾选一项,再进行操作',
                type: 'warning'
            });
        } else {
            this.speedupData();
        }
    },
}



操作完成后清除所勾选的选框








Logo

前往低代码交流专区

更多推荐