如何在React中映射3个数组

时间:2017-07-10 14:09:51

标签: javascript reactjs

我试试这个

test1: [1,2,3] //Array in constructor
test2: [4,5,6] //Array in constructor
test3:  [7,8,9] //Array in constructor

/

const postList = this.state.test1.map((dateList, titleList, storyList) =>
        <p>
            {dateList}
            <br />
            {this.state.test2[titleList]}
            <br />
            {this.state.test3[storyList]}
            <hr />
        </p>

    );

,结果仅显示数组test1和test2

1 个答案:

答案 0 :(得分:1)

map-function的第二个参数是index。你称之为titleList。将其重命名为index,然后将代码更改为:

const postList = this.state.test1.map((dateList, index) =>
        <p>
            {dateList}
            <br />
            {this.state.test2[index]}
            <br />
            {this.state.test3[index]}
            <hr />
        </p>

    );