Ich habe vor kurzem begonnen, React Native zu lernen und ich stolpere zu verstehen, was "diese" Keywords tut. Ich weiß, wie es in Java funktioniert, aber hier scheint es anders zu sein. Wenn jemand etwas für mich klären könnte, wäre ich sehr dankbar. Beispielcode:React Native dieses Schlüsselwort
-1
A
Antwort
0
this
Schlüsselwort in Java-Karten in der Regel an ihre Mutter Klasse.
in Javascript, es entspricht seinem Elternteil Funktion.
Es ist schön erklärt in MDN Docs
0
Sie müssen Ihre updateState-Funktion an den Kontext in der Renderfunktion binden. Sie könnten auch Ihren updateState-Funktionsreiniger definieren.
Beachten Sie die .bind(this)
;
import React, { Component } from 'react'
import { Text, View } from 'react-native'
class Home extends Component {
state = {
myState: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.'
}
updateState() {
this.setState({ myState: 'The state is updated' })
}
render() {
return (
<View>
<Text onPress = {this.updateState.bind(this)}>
{this.state.myState}
</Text>
</View>
);
}
}
export default Home;
Mehr Infos here
Verwandte Themen
- 1. Dieses Schlüsselwort in C#
- 2. Dieses Schlüsselwort für Objektliteral
- 3. Javascript: Konstruktorfunktion dieses Schlüsselwort
- 4. Node.js dieses Schlüsselwort
- 5. Java-Vererbung - dieses Schlüsselwort
- 6. Dieses Schlüsselwort für Funktionsparameter
- 7. Dieses Schlüsselwort in Java
- 8. IDA pro 'dieses' Schlüsselwort
- 9. React Native - Webview Aufruf React Native Funktion
- 10. Verständnis "dieses" Schlüsselwort in libgdx
- 11. Dieses Schlüsselwort wird das falsche
- 12. java dieses Schlüsselwort in Konstruktor
- 13. Clojure gen-class dieses Schlüsselwort
- 14. React-Native: Dismiss/Exit React-Native Ansicht zurück zu Native
- 15. react-native init spezifizieren react version und react-native version
- 16. React Native - Native UI Komponenten
- 17. React/React-Native Refs [FIXED]
- 18. react-native: react-navigation schubladenetiketten
- 19. Hochstellige React-Native Text
- 20. React Native Lightbox
- 21. React Native - Cache DOM?
- 22. Geofencing in React Native
- 23. this.setState React Native
- 24. vscode react-native: launchReactNative.js
- 25. React Native Init Hanging
- 26. Montagekomponenten in React Native
- 27. React-Native + crypto: Wie man HMAC in React-Native erzeugt?
- 28. React Native: ADB-Problem für create-react-native-app
- 29. Neues React Native Projekt mit alter Version von react native
- 30. Implementierung von Firebase Auth mit React Native + react-native-oauth
https://stackoverflow.com/questions/4195970/what-does-this-mean In MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Referenz/Operatoren/dieses –
Mögliches Duplikat von [Was bedeutet "das"? (Https://stackoverflow.com/questions/4195970/what-does-this-mean) – Maluen
Es funktioniert genau gleich ... 'this' ist ein Verweis auf Ihren aktuellen Klassenkontext –