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

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

TypeError : ...map 不是函數(shù) - react.js

TypeError : ...map 不是函數(shù) - react.js

開滿天機 2021-11-12 16:49:58
在我的react.js應用程序中,我有一個這樣的功能:state={   c:[]}classRoom(classRooms){    if(classRooms!==null)    {        const updatedClass = classRooms.map((classRoom)=>{            return <ClassRoomUnit displayName={"as"} classID={"asdsa"} />;            //return <li>{classRoom}</li>;        });    }}在我的render方法中,我有: render() {    return (        <div>                            {this.classRoom(this.state.c)}        </div>    );  }c 在 state 中定義,它是一個數(shù)組。但它給了我錯誤,說:classRooms.map is not a function
查看完整描述

1 回答

?
ibeautiful

TA貢獻1993條經(jīng)驗 獲得超6個贊

根據(jù)評論和 stackblitz 鏈接,問題是您沒有從函數(shù)內(nèi)部返回值


import React, { Component } from 'react';

import { render } from 'react-dom';

import Hello from './Hello';

import './style.css';


class ClassRoomUnit extends Component{

    displayName;

    classID;

    render() {

        return(

          <div>

            {this.props.displayName}

            {this.props.classID}

          </div>


        );

    }

}


class App extends Component {


  state={

    c:[1,2,3]

  }


  classRoom(classRooms)

    {

        console.log(classRooms);

        if(classRooms!==null)

        {

            const updatedClass = classRooms.map((classRoom)=>{

                return <ClassRoomUnit displayName={"as"} classID={"asdsa"} />;

            });

        }

        return updatedClass;

    }


  render() {

    return (

      <div>

        dynamic list start

        {this.classRoom(this.state.c)}

        dynamic list end


      </div>

    );

  }

}


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


查看完整回答
反對 回復 2021-11-12
  • 1 回答
  • 0 關(guān)注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

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