import React from 'react'import Item from './Item.jsx'class ItemPanel extends React.Component{constructor(){ super();}render(){ var items = []; if(this.props.items.length == 0){ items.push(<div>NO Record!</div>) }else{ this.props.items.forEach((v,i) => { items.push(<Item key={i} item={v}/>); }) } return ( <div> <div className='itemsPanel-top'> <span key="s1">name</span> <span key="s2">ID</span> <span key="s3">Six</span> <span key="s4">Age</span> <span key="s5">DEL</span> <span key="s6">DETA</span> </div> <ul className='itemsPanel-con'> {items} </ul> </div> )}}export default ItemPanel
1 回答
繁华开满天机
TA贡献1816条经验 获得超4个赞
<ul className='itemsPanel-con'>
{items}
</ul>
items是一个数组,渲染的时候都需要带上key,只有一项内容也需要:
items.push(<div key={1}>NO Record!</div>)
添加回答
举报
0/150
提交
取消