我正在尝试使用 react 创建简单表。我正在导入 CustomerList,然后循环遍历所有 Object.keys 以首先获取表标题,然后获取正文部分。当控制台登录时,我可以看到我所有的customerList属性都在那里,但是当 console.loging Object.keys 时它显示“未定义”,我不明白我在哪里犯了愚蠢的错误。对于我能得到的所有帮助,我将不胜感激。提前致谢!
我试过谷歌和 youtube 但没有得到我正在寻找的答案
export const customerList = [
{
name: "Anny Larsson",
age: 23,
id: 1,
title: "Title1",
accountNumber: "12345",
address: "Stockholm 14, Stockholm Sweden",
hobbyList:["coding", "writing", "reading", "skiing"],
emptyColumn: ""
},
{
name: "Helena hel",
age: 20,
id:2,
title: "Title2",
accountNumber: "22245",
address: "Stockholm City, Stockholm Sweden",
hobbyList:["coding", "Cooking", "games", "skiing"],
emptyColumn: ""
},
{
name: "Ayesha AAA",
age: 25,
id: 3,
title: "Title3",
accountNumber: "09845",
address: "Stockholm 21, Stockholm Sweden",
hobbyList:["coding", "Cooking", "games", "skiing"],
emptyColumn: ""
},
//more list goes here......
// ...............
];
export default customerList;
// My customerListTable.js
import React, { Component } from 'react';
import CustomerList from './CustomerList';
import CustomerTitle from './CustomerTitle';
class CustomerListTable extends Component {
state = {
customerList: CustomerList
}
componentDidMount(){
this.setState({
customerList: [...this.state.customerList] //copying the list
})
};
headerTitle = Object.keys(this.state.customerList[0]).map((header , index) => {
console.log("columnHeaderTitles ", this.headerTitle )
// return (
// <li>{header}</li>
// )
})
qq_笑_17
白衣非少年
相关分类