第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

通過(guò) Object.keys 循環(huán)時(shí),我的 ArrayList 顯示為空

通過(guò) Object.keys 循環(huán)時(shí),我的 ArrayList 顯示為空

眼眸繁星 2021-11-18 20:15:06
我正在嘗試使用 react 創(chuàng)建簡(jiǎn)單表。我正在導(dǎo)入 CustomerList,然后循環(huán)遍歷所有 Object.keys 以首先獲取表標(biāo)題,然后獲取正文部分。當(dāng)控制臺(tái)登錄時(shí),我可以看到我所有的customerList屬性都在那里,但是當(dāng) console.loging Object.keys 時(shí)它顯示“未定義”,我不明白我在哪里犯了愚蠢的錯(cuò)誤。對(duì)于我能得到的所有幫助,我將不勝感激。提前致謝!我試過(guò)谷歌和 youtube 但沒(méi)有得到我正在尋找的答案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.jsimport 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>        // )        })
查看完整描述

2 回答

?
qq_笑_17

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超7個(gè)贊

我認(rèn)為您的邏輯過(guò)于復(fù)雜,但您的代碼似乎有效。

只在你的 map 函數(shù)中返回一些東西將標(biāo)題添加到組件中:


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: ""

    }

];


class CustomerListTable extends React.Component {

    state = {

        customerList: CustomerList

    }

    

    headerTitle = Object.keys(this.state.customerList[0]).map((header) => {

        return (<li key={header}>{header}</li>)

    })


    render() {

        return (<div>

            <h1>Customer table....</h1>

            <div>


                <table>

                    <thead>

                        <tr>

                            <th>{this.headerTitle}</th>


                        </tr>

                    </thead>


                    <tbody></tbody>

                </table>


            </div>


        </div>);

    }

}


ReactDOM.render(<CustomerListTable/>, document.getElementById('root'));

<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>

<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>

<div id="root"></div>


查看完整回答
反對(duì) 回復(fù) 2021-11-18
?
白衣非少年

TA貢獻(xiàn)1155條經(jīng)驗(yàn) 獲得超0個(gè)贊

const customerList = [

    {

        name: "Anny Larsson",

        age: 23,

        id: 1,

        title: "Title1",

        accountNumber: "12345",

        address: "Stockholm 14, Stockholm Sweden",

        hobbyList:["coding", "writing", "reading", "skiing"],

        emptyColumn: ""

    }

];

const headerTitle = Object.keys(customerList[0]).map((header , index) => header)

console.log(headerTitle)


在Thead Table,映射headerTitle創(chuàng)建動(dòng)態(tài)th:


<thead>

    <tr>

    {

       this.headerTitle.map((item, index) => <th key={index}>{item}</th>)        

    }

    </tr>

</thead>


查看完整回答
反對(duì) 回復(fù) 2021-11-18
  • 2 回答
  • 0 關(guān)注
  • 223 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)