首页 > 解决方案 > Wix 代码/为什么全选按钮不全选?

问题描述

我已经全选并删除了复选框的所有按钮。你可以看到下面的代码。但是错误是他应该选择所有选项(不是复选框中的所有选项。)为什么复选框不选择所有选项?有什么不足

详情 https://www.wix.com/velo/forum/community-discussion/why-doesn-t-the-select-all-button-select-all [![在此处输入图片描述][1]][1 ]

我的代码

export function CountrySelectAllt_click(event) {

 // number of items in checkbox group
 let totalItems = $w('#checkboxt1'+ ", " +'#checkboxt2'+ ", " +'#checkboxt3'+ ", " 
+'#checkboxt4').options.length;  
 // initiate a newIndices array to hold all indices
 let newIndices = [];
 for (var i = 0; i < totalItems; i++) {
     newIndices.push(i); 
  }
  console.log(newIndices);
  $w('#checkboxt1').selectedIndices = newIndices;
  $w('#checkboxt2').selectedIndices = newIndices;
  $w('#checkboxt3').selectedIndices = newIndices;
  $w('#checkboxt4').selectedIndices = newIndices;

}

 export function CountrySelectAlltreset_click(event) {

 // number of items in checkbox group
 let totalItems = $w('#checkboxt1'+ ", " +'#checkboxt2'+ ", " +'#checkboxt3'+ ", " 
+'#checkboxt4').options.length;  
// initiate a newIndices array to hold all indices
 let newIndices = [];
 for (var i = 0; i < totalItems; i++) {
     newIndices.push(i); 
  }
  console.log(newIndices);
  $w('#checkboxt1').selectedIndices = [];
  $w('#checkboxt2').selectedIndices = [];
  $w('#checkboxt3').selectedIndices = [];
  $w('#checkboxt4').selectedIndices = [];

}

  [1]: https://i.stack.imgur.com/mQBT8.jpg

标签: javascriptselectcheckboxvelo

解决方案


在我看来,您正在混合 Checkboxes 和 CheckboxGroup 属性。Checkboxes 和 CheckboxGroups 是不同类型的元素。

似乎您已经添加了 Checkbox 元素,因为您列出了一堆 ID。但是随后您使用的selectedIndices属性是 CheckboxGroup 属性。


推荐阅读