简体   繁体   English

undefined 不是一个函数(靠近'...datas.map ....')

[英]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.

相关问题 未定义不是 function(靠近'... map ...') - Undefined is not a function (near '… map …') TypeError: undefined is not a function ('...data.map...'附近) - TypeError: undefined is not a function (near '…data.map…') 类型错误:未定义不是函数(靠近“...todos.map...”) - TypeError: undefined is not a function (near '...todos.map...') TypeError: undefined is not a function(靠近'...currencyFilter.map...') - TypeError: undefined is not a function (near '…currencyFilter.map…') undefined 不是 function ('...this.state.results.map...' 附近) - undefined is not a function (near '…this.state.results.map…') TypeError: undefined is not a function (near &#39;...productsCtg.map...&#39;) 反应原生 - TypeError: undefined is not a function (near '...productsCtg.map...') react native TypeError: undefined is not a function ('...this.state.profile.map...'附近) - TypeError: undefined is not a function (near '…this.state.profile.map…') Undefined 不是 function('...item.map...' 附近)-React Native 搜索栏 - Undefined is not a function (near '…item.map…')-React Native search bar React - “TypeError: undefined is not a function (near '...formFields.map...')” - React - “TypeError: undefined is not a function (near '…formFields.map…')” React native Undefined 不是函数(&#39;...data.map...&#39; 附近) - React native Undefined is not a function (near '...data.map...')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM