ReactJS:我如何将变量传递给另一个函数

时间:2017-11-30 02:25:48

标签: javascript reactjs

我打算做的就是将map方法中定义的变量(list)传递给另一个函数,以便在编辑click事件后使该值成为默认值,我能够通过{{ 1}}(不是通过value属性,而是通过innerText,需要知道原因?),但是,点击“保存”按钮后会抛出错误消息ref这里是我的代码:

PARENT:

innerText is not defined

儿童:

export default class Parent extends Component {
  constructor(props){
    super(props);
    this.state = {
       todoArr: [],
    }

   this.editTo = this.editTo.bind(this);
  }

editTo(text, i) {
   var lists = this.state.todoArr;
   lists[i] = text;
   this.setState({todoArr: lists})
 }
render() {
    return (
      <div>
       <form>
        <Children {...this.state} EditTodos={this.editTo}/>
       </form>
      </div>
    )
  }

我不确定如何将export default class Children extends Component { constructor(props) { super(props); this.state = { editing: false, }; } handleSave(e) { e.preventDefault(); this.props.EditTodos(this.refs.textVal.innerText, i) } render_Display() { return( <div> { this.props.listArr.map((list,i) => { return( <div key={i} index={i} ref="textVal" id="_list"> <li>{list}</li> </div> )}) } </div> ); } render_Form() { return( <div> <textarea defaultValue={this.refs.textVal.innerText}/> //this.refs.textVal.value is not working <button onClick={(e) => this.handleSave(e)} className="btn btn-success btn-xs glyphicon glyphicon-floppy-disk" /> </div> ) } 传递给handleSave以保存正确的索引待办事项,提前致谢

0 个答案:

没有答案