亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

React中的渲染對象屬性

React中的渲染對象屬性

我有一個這樣的物體export const otherInformation = [{    "FAQ": ['Getting started guide', 'Selling policy'],    "Help & Support": ['Help guide', 'Selling policy'],    "Legal": ['Terms of Use', 'Privacy Policy']}]我的密碼class Information extends Component {    render() {        const otherInformationLoop = otherInformation.map((value, key) => {            return (                <div>                    <div className="col-md-4" key={key}>                        <div className="dashboard-info">                            {Object.keys(value).map((val, k) => {                                return (<h4 k={k}>{val}</h4>)                                })                            }                        </div>                    </div>                </div>            )        })        return (            { otherInformationLoop }            // <div></div>        );    }}我在遍歷對象時遇到麻煩。獲得的錯誤是這樣的Information.render(): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object我如何循環通過該對象,以便獲得所獲得的結果提前致謝。任何幫助表示贊賞
查看完整描述

2 回答

?
繁星淼淼

TA貢獻1775條經驗 獲得超11個贊

您正在渲染數組,但只能從react組件返回一個塊,將map函數包裝在div中


class Information extends Component {

    render() {

        const otherInformationLoop = otherInformation.map((value, key) => {

            return (

                <div>

                    <div className="col-md-4" key={key}>

                        <div className="dashboard-info">


                            {Object.keys(value).map((val, k) => {

                                return (<h4 k={k}>{val}</h4>)

                                })

                            }


                        </div>

                    </div>

                </div>

            )

        })


        return (


            <div>{ otherInformationLoop }</div>

        );

    }

}


查看完整回答
反對 回復 2019-11-20
?
qq_花開花謝_0

TA貢獻1835條經驗 獲得超7個贊

實際上,render方法返回的對象只有一個otherInformationLoop屬性。只需返回該值,而無需任何括號即可在React 16+中使用(但每個外部div都需要一個關鍵道具)

查看完整回答
反對 回復 2019-11-20
  • 2 回答
  • 0 關注
  • 1372 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號