react迴圈陣列,根據資料內容,新增物件屬性,動態設定icon
阿新 • • 發佈:2021-01-25
技術標籤:reactjs
var newPoiTypeList = data.response;
newPoiTypeList .forEach(function (val, idx, arr) {
if (val.type_name == '公交站') {
val.icon = ""
}
})
this.setState({
poiTypeList: newPoiTypeList,
})
// render
{this.state.poiTypeList.map((i, index) => {
return (
<li className="poi_icon" onClick={this.poiTypeOn.bind(this, index, i.type_id, i.type_name)} >
<p ><i className="iconfont" dangerouslySetInnerHTML= {{ __html: i.icon }}></i></p>
<p>{i.type_name}</p>
</li>
)
})}