react列表

react

实例1

<div id="example"></div>

<script type="text/babel">

const numbers = [1, 2, 3, 4, 5];

const listItems = numbers.map((numbers) =>

<li>{numbers}</li>

);

ReactDOM.render(

<ul>{listItems}</ul>,

document.getElementById('example')

);

</script>

实例2

function NumberList(props) {

const numbers = props.numbers;

const listItems = numbers.map((number) =>

<li key={number.toString()}>

{number}

</li>

);

return (

<ul>{listItems}</ul>

);

}

const numbers = [1, 2, 3, 4, 5];

ReactDOM.render(

<NumberList numbers={numbers} />,

document.getElementById('example')

);

实例3

<div id="example"></div>

<script type="text/babel">

function ListItem(props) {

return <li>{props.value}</li>;

}

function NumberList(props) {

const numbers = props.numbers;

const listItems = numbers.map((number) =>

<ListItem key={number.toString()}

value={number} />

);

return (

<ul>

{listItems}

</ul>

);

}

const numbers = [1, 2, 3, 4, 5, 6];

ReactDOM.render(

<NumberList numbers={numbers} />,

document.getElementById('example')

);

</script>

以上是 react列表 的全部内容, 来源链接: utcz.com/z/382145.html

回到顶部