Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 未定义的错误不是一个函数_Reactjs_React Native - Fatal编程技术网

Reactjs 未定义的错误不是一个函数

Reactjs 未定义的错误不是一个函数,reactjs,react-native,Reactjs,React Native,我通过以下道具传递阵列: { id: 1, Name: "Abe", HitPointValue: "124", StrengthValue: "12", IntelligenceValue: "14", WisdomValue: "16", DexterityValue: "12", ConstitutionValue: "10", CharismaValue: "17", Avatar: require('./i

我通过以下道具传递阵列:

{
    id: 1,
    Name: "Abe",
    HitPointValue: "124",
    StrengthValue: "12",
    IntelligenceValue: "14",
    WisdomValue: "16",
    DexterityValue: "12",
    ConstitutionValue: "10",
    CharismaValue: "17",
    Avatar: require('./images/avatar_1.jpg')
}
static navigationOptions = ({ navigation }) => {
    const {char} = state.params;
}
render() {
    const { params } = this.props.navigation.state;
    return (
        <View>
            {Object.entries(params.char).map(([key,value], index) =>
                <Text key={key}>
                    {key} : {value} {"\n"}
                </Text>
            )}
        </View>
    )
 }
我在这样一个组件中接收这些信息:

{
    id: 1,
    Name: "Abe",
    HitPointValue: "124",
    StrengthValue: "12",
    IntelligenceValue: "14",
    WisdomValue: "16",
    DexterityValue: "12",
    ConstitutionValue: "10",
    CharismaValue: "17",
    Avatar: require('./images/avatar_1.jpg')
}
static navigationOptions = ({ navigation }) => {
    const {char} = state.params;
}
render() {
    const { params } = this.props.navigation.state;
    return (
        <View>
            {Object.entries(params.char).map(([key,value], index) =>
                <Text key={key}>
                    {key} : {value} {"\n"}
                </Text>
            )}
        </View>
    )
 }
当我像这样一个接一个地写出数组的属性时,它是有效的:

    render() {
        const { params } = this.props.navigation.state;
        return (
            <View>
                <Text>
                    Name: {params.char.Name}{"\n"}
                </Text>
            </View>
        )   
}
render(){
const{params}=this.props.navigation.state;
返回(
名称:{params.char.Name}{\n}
)   
}
但是当我尝试使用“map”在数组中循环时(如下所示),我只得到一个错误

undefined不是函数(params.char.map)

render(){
const{params}=this.props.navigation.state;
返回(
{params.char.map(c=>
{c.key}:{c.value}{“\n”}
)}
)
}
我试着按照这个指南去做,但它不起作用

我可能做错了什么


谢谢!

因为数据不是数组,而
映射
仅适用于
数组
。请先使用
映射

这样写:

{
    id: 1,
    Name: "Abe",
    HitPointValue: "124",
    StrengthValue: "12",
    IntelligenceValue: "14",
    WisdomValue: "16",
    DexterityValue: "12",
    ConstitutionValue: "10",
    CharismaValue: "17",
    Avatar: require('./images/avatar_1.jpg')
}
static navigationOptions = ({ navigation }) => {
    const {char} = state.params;
}
render() {
    const { params } = this.props.navigation.state;
    return (
        <View>
            {Object.entries(params.char).map(([key,value], index) =>
                <Text key={key}>
                    {key} : {value} {"\n"}
                </Text>
            )}
        </View>
    )
 }

params.char
中会包含什么?映射是对
数组
类型的补充