[英]undefined is not a function(near '...datas.map....')
This is my data这是我的数据
[{"size":"Small","price":"90"},{"size":"Large","price":"180"},{"size":"Extra Large","price":"200"}]
and this is my code这是我的代码
const route = useRoute();
const [datas, setDatas] = useState([]);
useEffect(() => {
setDatas(route.params.item_sizes);
},[])
const ItemSizes = () => {
if(datas.length > 0)
{
console.log("Item size data: ", datas); //for debugging purposes
return(
<View>
{datas.map((data,key) => (
<View key={key}>
<View style={{flex:0.2}}>
<MaterialCommunityIcons name={"radiobox-blank"} size={20} color={'gray'}/>
{/* <Text style={{fontSize:16, fontWeight:'bold'}}>Icon</Text> */}
</View>
<View style={{flex:1}}>
<Text style={{fontSize:16, fontWeight:'bold'}}>{data.size}</Text>
</View>
<View style={{flex:1, flexDirection:'row-reverse'}}>
<Text style={{fontSize:16, fontWeight:'bold'}}>{data.price}</Text>
</View>
</View>
))}
</View>
)
}
}
I call it from my view like this我这样称呼它
return (
<View>
{ItemSizes()}
</View>
)
So after I checked there's a data on datas
so why it is undefined?因此,在我检查了
datas
上有一个数据之后,为什么它是未定义的? Please do explain why it is returning me undefined even though there's a data??请解释为什么它返回我未定义即使有数据? Thank you
谢谢
Check if the data you are setting is an array or string.检查您设置的数据是数组还是字符串。 If it's string set it like below by parsing
如果它是字符串,则通过解析将其设置为如下所示
setData(JSON.parse(route.params.item_sizes));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.