react基础(5)—— 循环

react中的循环需要我们使用ECMA中的方法进行操作,没有提供内置的方法,

这里面我们使用数组的方法进行循环   -----    {arr.map()}

 

###################循环##############################

import React,{Component} from "react";
import "./index.scss"

class Nowplaying extends Component {
constructor(props){
super(props)
this.state={
nowplayList:["1111","2222","3333","4444"]

//以后这个状态通过ajax动态获取,然后通过this.setState=({})来复制
}
}
render(){
return <div id="Nowplaying">
<ul>
{ {/*不设置key值会有warning*     -----   在操作数组的时候使用不会改变原数组的方法/}
this.state.nowplayList.map(item=>
<li key={item}>{item}</li>
)
}
</ul>
</div>
}
}

export default Nowplaying;

posted on 2018-10-25 16:50  杨学友  阅读(612)  评论(0编辑  收藏  举报

导航