Javascript 选中所有方法复选框,不应在vue.js中选择禁用的checbox
我在表格中有一个带有复选框的列表,当我单击“全选”功能时,它会选中所有复选框,包括禁用的复选框,我需要排除禁用的复选框Javascript 选中所有方法复选框,不应在vue.js中选择禁用的checbox,javascript,vue.js,vue-component,Javascript,Vue.js,Vue Component,我在表格中有一个带有复选框的列表,当我单击“全选”功能时,它会选中所有复选框,包括禁用的复选框,我需要排除禁用的复选框 <li><a @click.prevent="selectAll" id="cardSelectAllAId"> SelectAll</a></li> <single-checkbox class="checkbox " inputId="card
<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;
}
},
选择全部
selectAll(){
for(设i=0;i
您可以在函数中尝试类似的操作-
// 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);
这是有效的您尝试过什么?它应该很简单,只要将if条件更改为类似于
if(this.cards[i].selected!==undefined&&this.cards[i].licenceEnabled)
。此外,您的逻辑使用card[i]
但是在模板中它被用作卡。数据卡在模板中从哪里来?卡来自数据源道具。这种情况不起作用,我以前尝试过获取类名并检查它是否被禁用或不被理解。每个卡项是否都有数据字段?另一个小字段需要注意的是:在子组件内部对传入的道具表单进行变异可能不是一个好主意。可能有更好的方法做到这一点。是的,它确实有数据
if(this.cards[i].selected !== undefined && this.cards[i].licenseEnabled)