React js で useState を使用してオブジェクトのキー値を更新する方法
P粉066725148
P粉066725148 2023-09-13 21:31:08
0
1
534

const Row  = [
        {
            name: "jad",
            link :"/jad",
            calories :"52",
            Fat :"4",
            Carbs :"5",
            Protein :"41"
        },
        {
            name: "john",
            link :"/john",
            calories :"82",
            Fat :"42",
            Carbs: "35",
            Protein :"1"
        }
] 

const [myList, setMyList] =  React.useState(Row);
function handle(){
  setMyList()
}
<TableBody>
        {
            myList.map((item)=> {
              return (
                <TableRow>
                    <TableCell><Link href={item.link}>{item.name}</Link></TableCell>
                    <TableCell align="right">{item.calories}</TableCell>
                    <TableCell align="right">{item.Fat}</TableCell>
                    <TableCell align="right">{item.Carbs}</TableCell>
                    <TableCell align="right">{item.Protein}</TableCell>
                     <TableCell align="right"><Button variant="contained">Edit</Button><Button variant="outlined" startIcon={<DeleteIcon />}>
  Delete</Button></TableCell>
                </TableRow>
              )
            })
        }
        </TableBody>

P粉066725148
P粉066725148

全員に返信(1)
P粉683665106

ループによって myList を解析し、特定のキーを見つけて、キーの新しい値を更新し、更新された myList setMyList を使用します。

いいねを押す +0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!