从ReactJs组件获取数据并从中传递数据

时间:2015-10-02 17:37:49

标签: javascript reactjs

我正在尝试弄清楚如何在警报窗口上设置消息,并在调用“addSkill”操作时根据用户的交互从中恢复成功或失败消息。我有下面的alertmodal和addskill操作的代码:

添加技能动作:

addSkill(e) {
    e.preventDefault();
    let id = guid();
    let skill_name = ReactDOM.findDOMNode(this.refs.skill_name).value.trim();
    ReactDOM.findDOMNode(this.refs.skill_name).value = '';
    ProfileDispatcher.dispatch({
      action: ADD_SKILL,
      new_skill: {
        name: skill_name
      }
    });
  }

AlertModal组件

class AlertModal extends React.Component {

  constructor() {
    super();
    this.state = {};
  }

  render() {

    if (this.props.show) {
        return (
        <div id="Backdrop" className={classnames('WindowBackdrop', this.props.color)}>
          <div className="WindowInnerBackdrop">
            <div id="AlertModal" className={classnames('Window', this.props.size, this.props.align)}>
              <h3 className="WindowHeading">{this.props.heading}</h3>
              <p>{this.props.message}</p>
               <div className="AlertModalFooter">
                 <button>Cancel</button>
                 <button>OK</button>
               </div>
             </div>
          </div>
        </div>
      );
    }
    return null;
  }
};

export default AlertModal;

0 个答案:

没有答案