2017-04-09 6 views
0
renderTaskSection() { 
    const { task, priority, isCompleted } = this.props; 

    const taskStyle = { 
     color: isCompleted ? 'green' : 'red', 
     cursor: 'pointer' 
    }; 

    if (this.state.isEditing) { 
     return (
      <td> 
       <form onSubmit={this.onSaveClick.bind(this)}> 
        <input type="text" defaultValue={task} ref="editInput" /> 
        <input type="text" defaultValue={priority} ref="editInput2" /> 
       </form> 
      </td> 
     ); 
    } 

    return (
     <div> 
     <td style={taskStyle} 
      onClick={this.props.toggleTask.bind(this, task)} 
     > 
      {task} 
     </td> 
     <td style={taskStyle} 
      onClick={this.props.toggleTask.bind(this, task)} 
     > 
      {priority} 
     </td> 
     </div> 
    ); 
} 

で​​制限を回避作業を、私はこのコード行を持って、私が各要素のTDを追加するたびに、私は1つのtd要素の代わりに、2を持っている場合、それは、問題のいくつかの種類が発生しているようです、 すべて順調。React.js

私はdiv内の要素をラップするとすべてが修正されると思っていましたが、間違っていました。なぜこれがReactで多くの問題を引き起こすのか不明です。特に、 。この簡単な回避策はありますか?

これらは、私は、Firefoxに乗るのメッセージの一部です。また

Warning: validateDOMNesting(...): <div> cannot appear as a child of <tr>. See TodosListItem > tr > div. bundle.js:11406:10 
Warning: validateDOMNesting(...): <td> cannot appear as a child of <div>. See TodosListItem > div > td. bundle.js:11406:10 
Error: findComponentRoot(..., .0.2.1.$1.0.0): Unable to find element. This probably means the DOM was unexpectedly mutated (e.g., by the browser), usually due to forgetting a <tbody> when using tables, nesting tags like <form>, <p>, or <a>, or using non-SVG elements in an <svg> parent. Try inspecting the child nodes of the element with React ID ``. bundle.js:10062:16 
[WDS] Disconnected! bundle.js:635:11 
saveTask bundle.js:28539:14 
Error: findComponentRoot(..., .0.2.1.$0.0.0): Unable to find element. This probably means the DOM was unexpectedly mutated (e.g., by the browser), usually due to forgetting a <tbody> when using tables, nesting tags like <form>, <p>, or <a>, or using non-SVG elements in an <svg> parent. Try inspecting the child nodes of the element with React ID ``. bundle.js:10062:16 
TypeError: onClickListeners[id] is undefined[Learn More] 

私はformタグで、独自のTDタグで囲まれた2つの入力を囲むとき、私は同様のエラーを取得します。

+1

あなたは 'tbody'とtr''で 'td'であなたのテーブル本体をラップする必要がありますし<tr>と呼び出しrenderを返します。ガイドについては、[here](https://github.com/mentrie/encrypt-ass/blob/master/d2/git-hub-events/src/index.js)を参照してください。 – Rowland

+0

フォームはどうですか? 2 tdをフォームの中に入れようとすると、これが表示されます。警告:validateDOMNesting(...):

は、の子としては表示されません。 TodosListItem> tr>フォームを参照してください。 bundle.js:11406:10 警告:validateDOMNesting(...):​​はの子として表示されません。 TodosListItem> form> tdを参照してください。 – prog

+0

サンプルコードのjsfiddleを追加できますか? @prog – Rowland

答えて

1

変更このrenderTaskSection<tbody>のみ

render() { 
    <table> 
     <tbody> 
      {this.renderTaskSection()} 
     </tbody> 
    </table> 
} 

renderTaskSection() { 
    const { task, priority, isCompleted } = this.props; 

    const taskStyle = { 
     color: isCompleted ? 'green' : 'red', 
     cursor: 'pointer' 
    }; 

    if (this.state.isEditing) { 
     return (
      <tr> 
       <td> 
        <form onSubmit={this.onSaveClick.bind(this)}> 
         <input type="text" defaultValue={task} ref="editInput" /> 
         <input type="text" defaultValue={priority} ref="editInput2" /> 
        </form> 
       </td> 
      </tr> 
     ); 
    } 

    return (
     <tr> 
      <td style={taskStyle} onClick={this.props.toggleTask.bind(this, task)}> 
       {task} 
      </td> 
      <td style={taskStyle} onClick={this.props.toggleTask.bind(this, task)}> 
       {priority} 
      </td> 
     </tr> 
    ); 
}