/ / jak wyczyścić programowo i wybrać elementy programowo - reaktjs, antd

jak programowo usuwać elementy antd select - reactjs, antd

Używam https://ant.design/components/select/

Jak mogę programowo usunąć wybrane elementy z <Select>?
Uwaga: <Option> nie jest wartością ciągu, ale Węzłem.

Odpowiedzi:

0 dla odpowiedzi № 1

Przypisanie wartości Select do stanu powinno działać. Wypróbuj coś takiego:

class Banana extends React.Component {
constructor() {
super();
this.state = {};

this.handleChange = this.handleChange.bind(this);
this.clearSelected = this.clearSelected.bind(this);
}

handleChange(value) {
this.setState({ selected: value });
}

clearSelected() {
this.setState({ selected: null });
}

render() {
return (
<div>
<Select value={this.state.selected} style={{ width: 120 }} onChange={this.handleChange}>
<Option value="jack">Jack</Option>
<Option value="lucy">Lucy</Option>
<Option value="disabled" disabled>Disabled</Option>
<Option value="Yiminghe">yiminghe</Option>
</Select>
<Button onClick={this.clearSelected}>clear selected</Button>
</div>
);
}
}

https://codepen.io/anon/pen/NwYdEx?editors=0010