reactjs - 如何使用 MaterialTable 屏蔽密码
问题描述
我正在使用 MaterialTable 并想要屏蔽列值,但我无法这样做。
你能帮忙吗?
我正在使用 MaterialTable 向用户展示应用程序。
import MaterialTable from "material-table";
function UserProfile() {
const [state, setState] = React.useState({
columns: [
{ title: "Logging Name", field: "name" },
{
title: "password",
field: "password",
}
],
data: [
{
name: "Dan",
password: "TopseCrets@1"
}]
return (
<div style={{ maxWidth: "100%" }}>
<MaterialTable
title="User List"
columns={state.columns}
data={state.data}
.
.
.
);
I want to see ***** instead of password for the corresponding field, password string should be displayed only when I try to edit the row.
解决方案
目前,material-table 不支持自定义密码字段。
我能够在https://gitter.im/material-table/Lobby?at=5ebbf9c82cf0da0ad9fda27c(材料表的聊天大厅)上挽救解决方案
简而言之,对于您的密码列,您要添加其他属性(渲染和编辑组件):
{
title: 'Password', field: 'password',
render: rowData => <p>{rowData.password.split('').map(() => '*')}</p>,
editComponent: props => (
<TextField
type="password"
value={props.value}
onChange={e => props.onChange(e.target.value)}
/>)
},
render 属性将在显示字段时替换字符。
editComponent 将使用您自己的 TextField 组件,在编辑行时键入“密码”以隐藏值。
推荐阅读
- javascript - Javascript JSON-如何映射到多个对象
- python - 扩展递归(库)函数,无需重复代码
- android - 旋转时的 Android XML 布局更改无法正常工作
- video - ffmpeg ssim 对高质量和低质量压缩都给了我不好的结果
- python - 根据更改的列条件设置多个列值
- awk - 打印文件的第一列和两列的减法加上一个更改分隔符的数字
- azure - Azure 流分析 - ARM 模板中的“继承分区”
- angular - Angular:变化检测
- spring-boot - 春季:Paypal Payment 新货币结果为 PENDING 捕获状态
- node.js - 通过node.js从mongodb获取数据