简体   繁体   English

Antd多重选择删除不再在选项列表中的值

[英]Antd multiple select remove values that are not in options list anymore

I have 2 selects, car brands and car models. 我有2个选择,汽车品牌和汽车型号。 List of models depends on which brands user selected. 型号列表取决于用户选择的品牌。

When user removes a brand, I update the options list for models, however, selected values remain even if they are no longer in the options list. 当用户删除品牌时,我会更新模型的选项列表,但是,即使它们不再出现在选项列表中,所选值仍然保留。

Is it possible to remove them automatically ? 是否可以自动删除它们?

You need to update the value of the model to the first element of the new model array. 您需要将模型的值更新为新模型数组的第一个元素。

something like: 就像是:

handleModelRemove = (value) => {
    // handle remove logic...
    this.setState({
      brand: selectedBrand,
      selectedModel: selectedBrand.models[0],
    });
  }

<Select value={this.state.selectedModel}>
          {modelOptions}
        </Select>

You will need to POST SOME CODE for better help. 您将需要发布一些代码以获得更好的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM