django - 表格中的可点击行
问题描述
我有一个用 Django 编写的后端,我正在使用 REST API 将它与 React 前端连接起来。我有一个表格,其中包含从我的 API 获取的数据。
问题是如何使这些行可点击,所以当我点击表格行时,我会获得有关该行代表什么的更多信息。我需要打开一个新页面,其中将显示有关该特定行的更多信息。
解决方案
要使一行可点击,只需将 onClick 属性添加到指向元素中的方法/函数的标记即可。像这样的东西:
import React, { Component } from 'react';
class App extends Component {
constructor(props){
super(props);
this.state={rowDetails:''};
this.doSomething=this.doSomething.bind(this);
}
doSomething=()=>{
this.setState({rowDetails:"the details about the clicked row"})
}
render(){
return(
<table>
<tr onClick={this.doSomething} >
<td>cell data</td>
<td>cell data</td>
</tr>
<p> {this.state.rowDetails} </p>
</table>
)
}
}
推荐阅读
- javascript - 从网站加载 HTML 文件,而不是在默认弹出框中加载 chrome 扩展名
- reactjs - React 材料表和 redux 开发工具
- oracle - 执行与编译存储过程
- laravel - 用数组更新多行
- llvm - 如何在 LLVM 中提取 Icmp inst 或 binaryOperator Inst 的目标位置?
- javascript - WebAssembly 中是否有 Javascript 运行时
- javascript - 我收到此错误:未捕获的 ReferenceError: $ is not defined at HTMLInputElement.onkeyup
- java - 在 Android 中的图像上添加圆圈
- ruby - 如何在 Ruby 中将两个 int 变量相乘
- python-3.x - Privnote 套接字服务器不理解请求