Office Fabric UI多选下拉列表自定义全选

时间:2019-03-25 03:43:13

标签: reactjs sharepoint-online spfx office-fabric

由于Office Fabric UI不具有此功能,因此我尝试创建一个功能是因为我们需要它。但它没有按预期的方式运行。我添加了“全部”键,所以当我选择它时,我将所有场所数组都添加到选择选项数组中,最后将其设置为状态。目前,状态已设置为状态,但是即使状态已在所有场所更新,也不会检查项目。我想念什么吗?

这是我的代码:

if(selectedOption.key == 'All'){
  let updatedSelectedItems = this.state.selectedVenues ? lodash.clone(this.state.selectedVenues) : [];
  let selectedVenueOps: IDropdownOption[] = [];
  if(selectedOption.selected){
    this.state.venues.forEach(v => {
      if(v.key !== 'All'){
        updatedSelectedItems.push(v.key.toString());
      }
      selectedVenueOps.push(v);
    });
  } else {
    this.state.venues.forEach(v => {
      let currIndex = updatedSelectedItems.indexOf(v.key.toString());
      if (currIndex > -1) {
        updatedSelectedItems.splice(currIndex, 1);
        selectedVenueOps.splice(currIndex, 1);
      }
    });
  }
  this.setState({
    selectedVenues: updatedSelectedItems,
    selectedVenueOptions: selectedVenueOps
  });
} else {
  let updatedSelectedItems = this.state.selectedVenues ? lodash.clone(this.state.selectedVenues) : [];
  let selectedVenueOps: IDropdownOption[] = [];
  if (selectedOption.selected) {
    updatedSelectedItems.push(selectedOption.key.toString());
    selectedVenueOps.push(selectedOption);
  } else {
    // remove the option if it's unchecked
    let currIndex = updatedSelectedItems.indexOf(selectedOption.key.toString());
    if (currIndex > -1) {
      updatedSelectedItems.splice(currIndex, 1);
      selectedVenueOps.splice(currIndex, 1);
    }
  }

  this.setState({
    selectedVenues: updatedSelectedItems,
    selectedVenueOptions: selectedVenueOps
  });
}  

enter image description here

enter image description here

0 个答案:

没有答案