簡體   English   中英

React Native,意外的關鍵字“This”

[英]React Native, Unexpected Keyword “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>

    );
}}

我基本上從this.props.detail.country的第一個和第二個實例中刪除了周圍的大括號。在 JS 中,這些大括號是 object 表示法並且缺少屬性名稱。 第三個實例是 JSX 模板變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM