我是 React-Native 的新手。我正在嘗試將資料映射到視圖中。一直試圖解決這個問題,通讀了檔案和其他資源,但沒有成功。我在這里做錯了什么?
資料
const data = [
{
id: "1",
title: "Online Appointment",
body: "Select the specialist and make an appointment through our App!",
image: "../../../assets/images/intro1.png",
},
{
id: "2",
title: "Emergency Call",
body: "Just In One Click Our Quick Response Team Will Provide You First Aid!",
image: "../../../assets/images/intro2.png",
},
{
id: "3",
title: "Online Pharmacy",
body: "You Can Buy and Sell Medical Equipments Through Our App!",
image: "../../../assets/images/intro3.png",
},
]
我正在使用這些資料來映射這里:
{data.map((id, title, body, image) => {
return (
<View style={TOPCOLUMN} key={id}>
<ImageBackground source={{ uri: image }} style={INTROIMAGE}>
<Text style={TITLE}>{title}</Text>
<Text style={CONTENT}>{body}</Text>
</ImageBackground>
</View>
)
})}
我得到的錯誤
Argument of type '(id: any, title: any, body: any, image: any) => Element' is not assignable to parameter of type '(value: { id: string; title: string; body: string; image: string; }, index: number, array: { id: string; title: string; body: string; image: string; }[]) => Element'.
uj5u.com熱心網友回復:
你忘了破壞
{data.map((id, title, body, image) => {
應該
{data.map(({id, title, body, image}) => {
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/316875.html
