res[0].timeline.forEach(item =>{
var arr = item.time.split("-")
that.option.xAxis[0].data.push(arr[1])
})
解析:forEach遍历res[0].timeline数组。[{time:12-2,index:0}....]
item替代数组的每一项。
item.time代表着每一项的time属性。
item.time.split("-")代表以 - 为分隔符,对item.time进行切割。
所以arr数组会是[12,2],split将其切割成两部分。
最后,that.option.xAxis[0].data.push(arr[1])把arr数组的第二项push近去就OK
遍历并切割字符串
最新推荐文章于 2020-11-19 11:02:20 发布