簡體   English   中英

在React中將數組傳遞給組件屬性

[英]Passing array to component property in React

如何將數組作為屬性傳遞給組件。 以下兩點都沒有實現我想要的。 我想傳遞項目數組,在組件中操作它們並在render方法中輸出。

<List columns=['one', 'two', 'three', 'four'] /> // unexpected token
<List columns="['one', 'two', 'three', 'four']" /> // passed through as string not array

對於這種事情,是否有標准語法或最佳實踐?

你需要在js表達式周圍使用{}

<List columns={['one', 'two', 'three', 'four']} />

暫無
暫無

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

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