Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.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。在我的代码中,我有一个表组件和多个页面。所以,每当我需要在表中显示数据时,我都使用相同的表组件。现在在某个页面中,当我删除一行时,我只想更改该行的颜色/更改该行的背景色。在其他页面中,我没有任何删除选项 为了显示数据,我使用“office ui fabric react/lib”中的DetailList。谁能帮我,我怎么解决我的问题?我应该使用onRenderRow吗?如何操作?您可以尝试执行以下操作: 在您的特定页面中: changeBackgroundColor(ev

我最近开始做react。在我的代码中,我有一个表组件和多个页面。所以,每当我需要在表中显示数据时,我都使用相同的表组件。现在在某个页面中,当我删除一行时,我只想更改该行的颜色/更改该行的背景色。在其他页面中,我没有任何删除选项


为了显示数据,我使用“office ui fabric react/lib”中的DetailList。谁能帮我,我怎么解决我的问题?我应该使用onRenderRow吗?如何操作?

您可以尝试执行以下操作:

在您的特定页面中:

changeBackgroundColor(event){
  // do sth with the clicked row
}

<YourTableComponent click={(event) => this.changeBackgroundColor(event)} />
<table>
  <tr>
    <th>...</th>
  </tr>
  <tr onClick={this.props.click}>
    <td>...</td>
  </tr>
</table>
changeBackgroundColor(事件){
//用单击的行做某事
}
this.changeBackgroundColor(事件)}/>
在您的组件中:

changeBackgroundColor(event){
  // do sth with the clicked row
}

<YourTableComponent click={(event) => this.changeBackgroundColor(event)} />
<table>
  <tr>
    <th>...</th>
  </tr>
  <tr onClick={this.props.click}>
    <td>...</td>
  </tr>
</table>

...
...

老虎吃了我的山羊草。老虎现在在哪里?差不多是那么回事。你的问题很不清楚。为我们添加一些相关代码,以便我们可以帮助您。您可以使用HOC通过共享代码的相同部分来抽象代码。