我在表中有一个带有复选框的列表,当我单击全选功能时,它会选择所有复选框,包括禁用的复选框,我需要排除禁用的复选框。
<li><a @click.prevent="selectAll" id="cardSelectAllAId">
SelectAll</a></li>
<single-checkbox class="checkbox "
inputId="card.data.id"
v-if="card.data.id"
@change="change(card.data)"
:value="card.data.selected"
:disabled="!card.data.licenseEnabled">
selectAll() {
for (let i = 0; i < this.cards.length; i += 1) {
if (this.cards[i].selected !== undefined) {
this.cards[i].selected = true;
}
},
答案 0 :(得分:0)
您可以在您的函数中尝试类似的操作
// Reset all selected first
this.cards.map((x) => x.selected = false);
// Filter and then set selected to true
this.cards
.filter((x) => x.data.licenseEnabled)
.map((x) => x.selected = true);
答案 1 :(得分:0)
if(this.cards[i].selected !== undefined && this.cards[i].licenseEnabled)
这有效