[uniapp] Click a way of writing multiple choices, and traverse the number of choices

<view class="header_box" v-for="(item,index) in lists" :key="index" @click="switchTab2(item)">
					<view class="one_text" style="position: relative;">
						<view class="one"></view>
						<view v-if="item.isTrue" class="two"></view>
					</view>
					<view class="one_text">{
   
   {namesel}}</view>
					<view class="one_text">{
   
   {item.name}}</view>
					<view class="one_text">{
   
   {item.phone}}</view>
		</view>

Two before and after the style change is:

.one {
				position: absolute;
				left: 96rpx;
				top: 18rpx;
				width: 28rpx;
				height: 28rpx;
				border: 1rpx solid #C0C0C0;
				border-radius: 50%;
			}

			.two {
				position: absolute;
				left: 100rpx;
				top: 22rpx;
				width: 20rpx;
				height: 20rpx;
				background: #FF7A00;
				border-radius: 50%;
			}

Fires when clicked:

switchTab2(item) {
						this.$set(item,'isTrue',!item.isTrue)
						console.log(item);
					},

Conditional traversal: find out the selection is true to get the ID number

let customerIds = []

this.lists.filter(res => res.isTrue).forEach(res => customerIds.push(res.ID))

Iterate through the number of selections:

    this.数量 = this.cusList.filter(res => res.isTrue).length

Guess you like

Origin blog.csdn.net/ONLYSRY/article/details/128023722