Ich möchte Dropdown in einem Formular löschen, wenn ein Benutzer auf Reset-Taste klickt.
Aber kann nicht herausfinden, wie man den Wert programmatisch einstellt.Semantic UI React, Wie programmatischer Wert in Dropdown auswählen?
1
A
Antwort
0
Schwierig, ohne den Code zu sehen, versuchen Einstellung 'value': []
1
SUIR verwendet deklarative API. Sie müssen HOC verwenden, um den Dropdown-Wert zu steuern.
Ich habe ein grundlegendes Beispiel gemacht, das zeigt, wie man damit umgeht.
const {
Button,
Container,
Divider,
Dropdown,
Label,
} = semanticUIReact
const options = [
{ value: 'all', text: 'All' },
{ value: 'articles', text: 'Articles' },
{ value: 'products', text: 'Products' },
]
class App extends React.Component {
constructor(props) {
\t \t super(props);
this.state = { value: 'all' }
}
reset() {
this.setState({ value: undefined })
}
setProducts() {
this.setState({ value: 'products' })
}
setValue(e, data) {
this.setState({ value: data.value })
}
render() {
const { value } = this.state
return (
<Container>
<Label content={`Current: ${value}`} />
<Divider />
<Dropdown
onChange={this.setValue.bind(this)}
options={options}
selection
value={value}
/>
<Divider />
<Button
content='Reset'
onClick={this.reset.bind(this)}
/>
<Button
content='Set products'
onClick={this.setProducts.bind(this)}
/>
</Container>
)
}
}
// ----------------------------------------
// Render to DOM
// ----------------------------------------
const mountNode = document.createElement('div')
document.body.appendChild(mountNode)
ReactDOM.render(<App />, mountNode)
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.15.0/lodash.min.js"></script>
<script src="https://unpkg.com/semantic-ui-react/dist/umd/semantic-ui-react.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.4/semantic.min.css">
Verwandte Themen
- 1. Wie Dropdown auf Standard-Wert in Semantic-UI-React wiederherstellen
- 2. Auswählen mehrerer Elemente semantic-ui dropdown
- 3. Semantic-UI Dynamic Dropdown
- 4. Semantic-UI-React Footer
- 5. Dropdown Semantic-UI
- 6. Semantic ui Akkordeon Dropdown
- 7. Semantic-UI Bildeigenschaften arbeiten nicht mit semantic-ui-react
- 8. Formularvalidierung mit Semantic-UI-React
- 9. Wie semantic-ui-react installieren und verwenden
- 10. Vue.js arbeitet nicht mit Semantic UI Dropdown
- 11. Wo Semantic UI Dropdown initialisieren in Reaktion
- 12. Reagieren und Semantic-Ui-Reagieren
- 13. Auswählen eines Semantic UI Drop-Down-Element mit Protractor
- 14. Filter ui-Auswahl Dropdown auf Geschwister basiert ui-Wert auswählen
- 15. Semantic UI umgeht Browserformularnachrichten
- 16. Semantic UI Dropdown - Bild als Symbol anzeigen?
- 17. React-Semantic-UI-Karten mit Pinterest Layout
- 18. Was sind "wie" Requisiten in Semantic-Ui-React-Komponenten?
- 19. Semantic UI Scrollable Segment
- 20. Semantic UI Dropdown - Wie positioniert man es links vom Eröffnungslink?
- 21. Wie man ein Semantic-Ui-React-Formular horizontal zentralisiert
- 22. Semantic UI Dropdown in ASP.Net MVC funktioniert nicht
- 23. Popup verwenden, um Eingabefehlermeldung in React-Semantic-UI anzuzeigen
- 24. Wie Dropdown-Wert auswählen und Dropdown mit angularjs auffüllen?
- 25. Semantic-u Dropdown funktioniert nicht
- 26. Semantic UI - Sidebar bricht festes Menü in React
- 27. semantic ui anpassen allowAdditions Nachricht
- 28. Semantic-Ui Drop-Down-Sizing
- 29. Semantic UI funktioniert überhaupt nicht
- 30. Semantic UI - Suchauswahl nicht suchend