Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.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 - Fatal编程技术网

Javascript 从其他组件获取值

Javascript 从其他组件获取值,javascript,reactjs,Javascript,Reactjs,我正在学习react,对于如何从其他组件获得价值有点困惑。我正在构建一个Podomoro时钟应用程序。这些措施包括: -设置会话时间, -设定休息时间, -倒计时的钟。 如何获得分配给时钟的会话时间和休息时间的值 这是我的密码: $(document).ready(function(){ var TimerSetting = React.createClass({ getInitialState: function(){ return { time: 0

我正在学习react,对于如何从其他组件获得价值有点困惑。我正在构建一个Podomoro时钟应用程序。这些措施包括: -设置会话时间, -设定休息时间, -倒计时的钟。 如何获得分配给时钟的会话时间和休息时间的值

这是我的密码:

$(document).ready(function(){
  var TimerSetting = React.createClass({
    getInitialState: function(){
      return {
        time: 0
      };
    },
    afterUpdateTime: function(callback){
      this.afterUpdateTimeAction = callback;
    },
    increment: function(){
      var time = this.state.time + 1;
      time = Math.max(time, 0);
      this.setState({
        time: time
      });
      this.afterUpdateTimeAction(time);
    },
    decrement: function(){
      var time = this.state.time - 1;
      time = Math.max(time, 0);
      this.setState({
        time: time
      });
      this.afterUpdateTimeAction(time);
    },
    render: function(){
      return (
        <div className="timerSetting">
          <div className="titleSetting">
            {this.props.title}
          </div>
          <div className="minus" onClick={this.decrement}>
            -
          </div>
          <div className="time-setting">
            {this.state.time}
          </div>
          <div className="plus" onClick={this.increment}>
          +
          </div>
        </div>
      )
    }
  });

  var PodomoroClock = React.createClass({
    getInitialState: function(){
      return {
        time: 0
      };
    },
    updateSession: function(time){
      this.setState({
        time: time
      });
    },
    render: function(){
      return(
        <div className="clock">
          {this.state.time}
        </div>
      );
    }
  });

  var TimerWrapper= React.createClass({
    updateClockSession: function(com){
      com.afterUpdateTime(this.updateChildSession);
    },
    updateChildSession: function(time){
      this.ref.podomoro.updateSession(time);
    },
    render: function(){
      return (
        <div className="timeWrapper">
          <div className="timer">
            <TimerSetting title="Session Length" ref={this.updateClockSession} />
            <TimerSetting title="Break Length" ref="break"/>
          </div>
          <div className="podomoroClock">
            <PodomoroClock ref='podomoro'/>
          </div>
        </div>
      );
    }
  });

  React.render(<TimerWrapper title="class2" />, $('#content')[0]);

});
$(文档).ready(函数(){
var TimerSetting=React.createClass({
getInitialState:函数(){
返回{
时间:0
};
},
afterUpdateTime:函数(回调){
this.afterUpdateTimeAction=回调;
},
增量:函数(){
变量时间=this.state.time+1;
时间=数学最大值(时间,0);
这是我的国家({
时间:时间
});
此。后更新措施(时间);
},
减量:函数(){
var time=this.state.time-1;
时间=数学最大值(时间,0);
这是我的国家({
时间:时间
});
此。后更新措施(时间);
},
render:function(){
返回(
{this.props.title}
-
{this.state.time}
+
)
}
});
var PodomoroClock=React.createClass({
getInitialState:函数(){
返回{
时间:0
};
},
updateSession:函数(时间){
这是我的国家({
时间:时间
});
},
render:function(){
返回(
{this.state.time}
);
}
});
var timerwraper=React.createClass({
UpdateLockSession:函数(com){
com.afterUpdateTime(this.updateChildSession);
},
updateChildSession:函数(时间){
此.ref.podomoro.updateSession(时间);
},
render:function(){
返回(
);
}
});
React.render(,$('#content')[0]);
});
我需要你的帮助?被它卡住了。我正在尝试使用回调,但它不起作用

请尝试以下方法:

<TimerSetting title="Session Length" onTimeChanged={this.updateClockSession} />
请注意,您的
timerRapper.onTimeChanged
函数现在将接收时间(整数)作为输入。

请尝试以下操作:

<TimerSetting title="Session Length" onTimeChanged={this.updateClockSession} />
请注意,
timerRapper.onTimeChanged
函数现在将接收时间(整数)作为输入