Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单个元素的更新状态(rest默认为常量)_Javascript_Reactjs_React Native_Expo - Fatal编程技术网

Javascript 单个元素的更新状态(rest默认为常量)

Javascript 单个元素的更新状态(rest默认为常量),javascript,reactjs,react-native,expo,Javascript,Reactjs,React Native,Expo,我试图使卡片可以点击和扩展,但当更新状态时,它会出现在所有的卡片上。我只想在一张卡上更改状态(发生事件的卡,在本例中为单击事件)。 但是,每隔一张卡的状态就会更新一次。目前,这对一个项目有效,但对其他项目也需要有效 export default class TransactionCards extends React.Component { constructor(props) { super(props); this.state = { isHidden: tr

我试图使卡片可以点击和扩展,但当更新状态时,它会出现在所有的卡片上。我只想在一张卡上更改状态(发生事件的卡,在本例中为单击事件)。 但是,每隔一张卡的状态就会更新一次。目前,这对一个项目有效,但对其他项目也需要有效

export default class TransactionCards extends React.Component {
constructor(props) {
    super(props);
    this.state = {
        isHidden: true
    };
}

toggleHidden() {
    this.setState({
        isHidden: !this.state.isHidden
    });
}
renderCards() {
    return this.props.data.map((card, index) => (
        <View key={card.id}>
            <View style={styles.dateContainer}>
                <Text style={styles.dateText}>{card.time}</Text>
            </View>
            <Card>
                <TouchableWithoutFeedback onPress={this.toggleHidden.bind(this)}>
                    <View>
                        <View>
                            <View style={styles.transactionContainer}>
                                <Image
                                    style={styles.countryImage}
                                    source={require("../../assets/images/us-country-icon.png")}
                                />
                                <Text style={styles.transactionTitle}>{card.title}</Text>
                                <Text style={styles.transactionAmount}>{card.cost}</Text>

                                <Icon
                                    name={card.transactionType == "debit" ? "log-out" : "log-in"}
                                    type="feather"
                                    color={card.transactionType == "debit" ? "red" : "green"}
                                    size={18}
                                    iconStyle={styles.transactionIcon}
                                />
                            </View>
                            <View>
                                <Text style={styles.transactionBankDetails}>{card.bankDetails}</Text>
                            </View>
                        </View>
                        {/* Setting visiblity condition */}
                        {!this.state.isHidden && (
                            <View>
                                <Divider style={styles.CardItemDivider} />
                                <View display="flex" flexDirection="row" justifyContent="space-between">
                                    <View>
                                        <Text style={styles.transactionBankDetails}>
                                            {card.transactionCategory}
                                        </Text>
                                        <Text style={styles.transactionBankDetails}>{card.accountName}</Text>
                                    </View>
                                    <View>
                                        <Icon name="bell" type="feather" iconStyle={styles.transactionIcon} />
                                    </View>
                                </View>
                            </View>
                        )}
                    </View>
                </TouchableWithoutFeedback>
            </Card>
        </View>
    ));
}

render() {
    return <ScrollView showsVerticalScrollIndicator={false}>{this.renderCards()}</ScrollView>;
}
导出默认类TransactionCards.Component{
建造师(道具){
超级(道具);
此.state={
伊希登:是的
};
}
切换隐藏(){
这是我的国家({
isHidden:!this.state.isHidden
});
}
renderCards(){
返回此.props.data.map((卡片,索引)=>(
{card.time}
{card.title}
{card.cost}
{card.bankDetails}
{/*设置可见性条件*/}
{!this.state.ishiden&&(
{card.transactionCategory}
{card.accountName}
)}
));
}
render(){
返回{this.renderCards()};
}

}

您有两个项目连接到同一状态的同一状态值。如果你想分离行为,你也必须分离价值观

您有两个项目连接到同一状态的同一状态值。如果你想分离行为,你也必须分离价值观

  • 为卡创建新组件并传递所需参数
  • 在卡组件内执行
    切换隐藏功能
  • 那么在这个文件里面应该是这样的

       <Card {SetYourPassedParams} />
       ......
    
    
    ......
    
  • 为卡创建新组件并传递所需参数
  • 在卡组件内执行
    切换隐藏功能
  • 那么在这个文件里面应该是这样的

       <Card {SetYourPassedParams} />
       ......
    
    
    ......
    
    您可以为每张卡在状态中添加一个单独的
    isHidden
    变量。您可以演示如何动态地添加多张卡吗?您可以为每张卡在状态中添加一个单独的
    isHidden
    变量。您可以演示如何动态地添加多张卡吗,您应该使用自己的“isHidden”属性和toggleHidden函数创建card类。然后在应用程序中插入所需的卡,对于每个按下的卡,将执行其toggleHidden,这将仅影响一张卡。例如,如果要以最佳方式执行此操作,应使用其自己的“isHidden”属性和toggleHidden函数创建卡类。然后在应用程序中插入所需的卡,对于每个按下的卡,将执行其切换隐藏,这将只影响一张卡,尤其是在一个文件中有多张卡<代码>…..
    。你必须为它创建一个组件并传递参数你在一个文件中有多张卡<代码>…..
    。您必须为它创建一个组件并传递参数