想在反应js中选择计算器中的运算符后得到我的下一个值

时间:2018-04-18 09:09:56

标签: reactjs

我陷入了如何从该变量中获取计算器中的下一个值,而该变量曾用于获取之前的值。

这是我的代码:

constructor(props)
{
    super(props)
    {
        this.state={
            value:'0',
            previousvalue:'',
            nextvalue:''
        }
    };
    this.handleclick=this.handleclick.bind(this);
    this.operation=this.operation.bind(this);
}

handleclick(digit)
{        
    this.setState({value:this.state.value==='0'?String(digit):this.state.value + digit});
    console.log('helo click fire',this.state.value);
    if(digit==='00')
    {
        this.setState({value:'0'});
        console.log('are you coming');
    }
}

operation(operator)
{
    console.log('operator coming',operator);
    // this.setState({ans:this.state.value,operator,this.state.value})
    const previousvalue=this.state.value;
    console.log('this is my previous value',previousvalue);
    if(operator)
    {
        const nextValue=this.state.value;
        console.log('this is my next value',nextValue);
        //it gives my previous value how i store init my new value ??
    }

}

如何从同一个变量中获取下一个值,它给出了我之前的值?

0 个答案:

没有答案