点击的按钮为必选状态

let total_selected = 0
//点击购物车确定按钮 判断用户选中的数量(必须手动勾选)
that.data.sku.tree.forEach(item => {
item.v.forEach(item => {
console.log(item)
if (item.isSelect == 'true') {
total_selected += 1
}
})
})
// 是否 等于数组的长度 如果不等于就提示 阻止用户确定
if (total_selected != that.data.sku.tree.length) {
wx.showToast({
title: '请选择规格'
})
return
}
if (that.data.sku.tree.length == 0) {
that.data.skuId = that.data.sku.list[0].id;
} else {
if (that.data.skuId == '') {
wx.showToast({
title: '请选择规格!',
icon: 'none',
})
return;
}
}

原文地址:https://www.cnblogs.com/xiaoxiaoxun/p/12118402.html