undefinedfix
Sign in

How to loop through the check box of element to get the selected data

Squallsq123 edited in Sat, 27 Aug 2022
<el-checkbox-group v-model="ruleForm.linecity">
                    <el-checkbox v-for=" city in ruleForm.linecity" :label="city" :key="city">{{city}}</el-checkbox>
                </el-checkbox-group>
                我的数据
                

ruleForm.linecity I get the data, and then I traverse the data. I want to transfer the 1234567 data in the data to the background, but every time I click the check box, all will be displayed. It should be a problem for me to write V-model binding

3 Replies
Nic
commented on Sat, 27 Aug 2022

CityList data

cityList: [
    {
        label: '广州',
        value: 1
    },
    {
        label: '北京',
        value: 3
    }
]
<el-checkbox-group v-model="ruleForm.linecity">
    <el-checkbox v-for="city in cityList" :label="city.value" :key="city.value">{{city.label}}</el-checkbox>
</el-checkbox-group>

last ruleForm.linecity That's the data you want

MiltonRose
commented on Sat, 27 Aug 2022

Don't use this for the V-model of El checkbox group ruleForm.linecity , another one

aleonjhon
commented on Sat, 27 Aug 2022

You first convert it to an array

lock This question has been locked and the reply function has been disabled.