我有 4 个按钮,每个按钮都有名称 id 和选定的布尔标志。
我想要实现的是,在单击按钮时,应该更改该特定按钮的布尔按钮标志。为此,我需要在 map 函数中为该特定按钮 Id 设置状态。
我的问题是我无法在地图函数中为那个特定的点击按钮设置状态,它的 btnSelected 应该改变
我的目标是创建一个多选取消选择按钮。它是用户感兴趣的选择,并基于此反映 UI 以及我的数组。这是我的代码。
感谢期待。
import React, { Component } from "react";
import { Redirect } from "react-router-dom";
export default class Test extends Component {
constructor(props, context) {
super(props, context);
this.handleChange = this.handleChange.bind(this);
this.state = {
value: "",
numbers: [1, 2, 3, 4, 5],
posts: [
{
id: 1,
topic: "Animal",
btnSelected: false
},
{
id: 2,
topic: "Food",
btnSelected: false
},
{
id: 3,
topic: "Planet",
btnSelected: …Run Code Online (Sandbox Code Playgroud)