【问题标题】:Get nested value of object with key field使用关键字段获取对象的嵌套值
【发布时间】:2021-06-01 23:03:00
【问题描述】:

我正在使用 material-ui 中的 DataGrid 来制作一个表格来显示我的数据。我遇到的问题是我有一个嵌套的数据数组,但是我无法使用 `

key field:
const columns = [
{ field: "Patient.full_name", headerName: "Full name patient", width: 130 },
{ field: "id_number", headerName: "id number", type: "number", width: 130 },];



export default function DataTable(props) {
const { exams } = props;


return (
    <div style={{ height: 400, width: "100%" }}>
        <DataGrid rows={exams} columns={columns} />
    </div>
);`

id_number 有效。但我似乎无法获得显示全名的嵌套值,我也尝试了“全名”、“患者:全名”。是否有可能在字符串字段中获取该值?

this is how the data is nested

【问题讨论】:

    标签: arrays reactjs datagrid material-ui


    【解决方案1】:

    这里, 字段:“Patient.full_name”将此字段值视为字符串。 您需要删除双引号并使其成为 Patient.full_name。

    const columns = [
    { field: Patient.full_name, headerName: "Full name patient", width: 130 },
    { field: "id_number", headerName: "id number", type: "number", width: 130 },];
    

    【讨论】:

    • 这将尝试访问专利变量,在这种情况下会破坏代码。
    猜你喜欢
    • 1970-01-01
    • 2020-02-24
    • 2019-09-26
    • 2016-10-31
    • 1970-01-01
    • 2019-07-08
    • 2018-10-24
    • 1970-01-01
    • 2022-01-15
    相关资源
    最近更新 更多