Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/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
Javascript 反应本机变量作用域_Javascript_Reactjs_React Native_Scope_React Props - Fatal编程技术网

Javascript 反应本机变量作用域

Javascript 反应本机变量作用域,javascript,reactjs,react-native,scope,react-props,Javascript,Reactjs,React Native,Scope,React Props,我有两个组件,一个是父级(ManySpace)和一个子级(OtherComponent)。OtherComponent为ManySpace道具渲染两个具有两个不同阵列的ManySpace组件 混淆第一个多空间和第二个多空间组件数组内容。 例如,MANYSPACE1 answer1=abc,MANYSPACE2 answer1=cba,两个ManySpace组件answer1的输出是相同的,不是预期值 我不使用const和let,因为在渲染范围之外使用变量,也不使用class变量,因为我使用的是这

我有两个组件,一个是父级(ManySpace)和一个子级(OtherComponent)。OtherComponent为ManySpace道具渲染两个具有两个不同阵列的ManySpace组件

混淆第一个多空间和第二个多空间组件数组内容。
例如,MANYSPACE1 answer1=abc,MANYSPACE2 answer1=cba,两个ManySpace组件answer1的输出是相同的,不是预期值

我不使用const和let,因为在渲染范围之外使用变量,也不使用class变量,因为我使用的是这样的prop赋值

MANYSPACE = this.props.manyspace;

onSubmitEditing1 = () => {
    if (secondinput) { this.secondref.focus(); }
    else if (thirdinput) { this.thirdref.focus(); }
    else { Keyboard.dismiss(); }
};
我如何解决这个问题谢谢。希望我能解释我的问题
多空间组件->

import React, { Component } from 'react'; //and other imports
let MANYSPACE;
let icerik;
let firsttext;
let firstinput;
let answer1;
let answerlength1;
let secondtext;
let secondinput;
class ManySpace extends Component {
    render() {
        MANYSPACE = this.props.manyspace;
        icerik = MANYSPACE[0].icerik;
        firsttext = MANYSPACE[0].firsttext;
        firstinput = MANYSPACE[0].firstinput;
        if (firstinput) {
            answer1 = MANYSPACE[0].firstinput.answer1;
            answerlength1 = answer1.length;
        }

        secondtext = MANYSPACE[0].secondtext;
        secondinput = MANYSPACE[0].secondinput;
        if (secondinput) {
            answer2 = MANYSPACE[0].secondinput.answer2;
            answerlength2 = answer2.length;
        }
        return ()
    }
}
--我的另一部分

import React, { Component } from 'react'; //and other imports
const MANYSPACE1 = [
    {
        icerik: 'lorem ipsum',
        firsttext: 'lorem ipsum',
        firstinput: {
            answer1: 'lorem ipsum'
        },
        secondtext: 'lorem ipsum'
    }
];

const MANYSPACE2 = [
    {
        icerik:'lorem ipsum',
        firsttext: 'lorem ipsum',
        firstinput: {
            answer1: 'lorem ipsum'
        },
        secondtext: 'lorem ipsum',
        secondinput: {
            answer2: 'lorem ipsum'
        },
        thirdinput: {
            answer3: 'lorem ipsum'
        }
    }
];  
class OtherComponent extends Component {
    <ManySpace
        manyspace={MANYSPACE1}
    />
    <ManySpace
        manyspace={MANYSPACE2}
    />
}
import React,{Component}来自'React'//及其他进口货品
常数MANYSPACE1=[
{
icerik:“lorem ipsum”,
第一个文本:“lorem ipsum”,
第一输入:{
回答1:“同侧眼”
},
第二个文本:“lorem ipsum”
}
];
常数MANYSPACE2=[
{
icerik:“lorem ipsum”,
第一个文本:“lorem ipsum”,
第一输入:{
回答1:“同侧眼”
},
第二个文本:“lorem ipsum”,
第二输入:{
回答2:“同侧眼”
},
第三句:{
回答3:‘lorem ipsum’
}
}
];  
类OtherComponent扩展组件{
}

为什么要将这些值保存在全局变量中?如果有多个
多个
实例,则不应将变量保留在组件之外,因为不同的实例将覆盖它们。“我使用渲染范围之外的变量,而不使用类变量”-好吧,这就是你的问题。不要这样做。我如何才能像在onSubmitEditing1函数中一样访问ManySpace类的变量我甚至无法通过完全破坏React的正常数据机制来理解您要做什么。