reactjs - React Table 中列值的字符串格式
问题描述
我正在使用反应表 V6。我有在表中显示为大写字符串的数据。我想做形成并显示成大写格式。这是反应表:
<ReactTable
filterable
data={items}
columns={[{
Header: "ID",
accessor: "id",
},{
Header: "Sale Status",
accessor: "sale_status",
style :{
'text-transform':'capitalized'
}
},
]} />
在销售状态数据显示为DESIGN_CONFIRMATION
我想显示为Design Confirmation
。请给我建议
解决方案
您需要编写一个实用函数来将字符串转换为您想要的格式。并在Cell
列定义的属性中使用它:
{
Header: "Sale Status",
accessor: "sale_status",
Cell: (row) => {
const sale_status = row.original.sale_status
if (!sale_status) return "";
return sale_status.split("_").map(w => w[0].toUpperCase() + w.substr(1).toLowerCase()).join(" ")
}
}
function toTitleCase(str, del = "_") {
if (!str) return "";
return str.split(del).map(w => w[0].toUpperCase() + w.substr(1).toLowerCase()).join(" ")
}
console.log(toTitleCase("ABCD_EFGH"))
console.log(toTitleCase("abcd_efgh"))
推荐阅读
- python-3.x - 如何将元组列表传递给python中的函数参数
- regex - 仅将文件的基本名称(不带扩展名的文件名)与正则表达式匹配
- css - 如何访问 css 样式 .advanced-pie-legend .legend-items-container .legend-items .legend-item?
- javascript - 为什么这个表单不会在 Laravel 中提交?
- python - 加入类似的 pandas DataFrame 列,对它们进行排序并填充 np.NaN
- python - MAWS.py IndexError:列表索引超出范围
- batch-file - 使用 .BAT 更改 txt 文件中的文本
- c - 任何人都可以提供有关猴子修补/挂钩 Ruby 的字符串 #{} 以进行插值的指导吗?
- python - SFTP 无法识别上传的文件
- html - 使用get elementbyID时如何隔离多个内文条目