javascript - React Native,意外的关键字“This”
问题描述
为什么我有一个红色错误标记这个关键字后面的点?它说(意外的关键字“这个”)
render() {
return (
<TouchableOpacity onPress={() => this.selectionOnPress({this.props.detail.country})}>
<Text style={[styles.btnSV, {
backgroundColor:
this.state.selectedButton === {this.props.detail.country} ? "red" : "grey"
}]}>
<Text style={styles.btnSV}>{this.props.detail.country}</Text>
</Text>
</TouchableOpacity>
);
}}
解决方案
尝试这个
render() {
return (
<TouchableOpacity onPress={() => this.selectionOnPress(this.props.detail.country)}>
<Text style={[styles.btnSV, {
backgroundColor:
this.state.selectedButton === this.props.detail.country ? "red" : "grey"
}]}>
<Text style={styles.btnSV}>{this.props.detail.country}</Text>
</Text>
</TouchableOpacity>
);
}}
我基本上从 Within JS 的第一个和第二个实例中删除了周围的大括号this.props.detail.country
,这些大括号是对象表示法并且缺少属性名称。第三个实例是 JSX 模板变量。
推荐阅读
- python - 是否可以在 python 中调试对象?
- arrays - PostgreSQL:如何对包含数组或数组的 json 列进行选择查询
- spring-boot - 使用 spring 数据使用 apache 进行缓存 ignite with spring boot
- r - 闪亮功能中的 SliderInput
- java - Cast unknown-int? element of HashMap to double
- spring - Why RememberMeAuthenticationFilter does not redirect to requested url?
- node.js - Is there a way to query a document based on a subdocument object ref?
- multithreading - How to properly stop a separate thread together with shutting down a bokeh server?
- c# - C# Static Function Library load at runtime?
- java - 如何在java中找到最后一个单词的长度?