我通过循环创建了HTML canvas标签,并且我也试图通过循环从DarkskyAPI设置该标签图标,但是它不会显示。
var skycons = new Skycons({"color": "white"});
skycons.set("icon0", Skycons = x.currently.icon); //the icon0 is hardcoded on html
skycons.play();
console.log(x.daily.data)
for(i=0;i<8;i++){
const canv = document.createElement('canvas')
canv.id = ('icons'+(i+1)) //i added +1 so the increment would be icon1, icon2
canv.height = 100
canv.width = 100
skycons.set('icons'+(i+1), Skycons = x.daily.data[i].icon) //but if i set the icon, match should be icon1 + x.daily.data[0].icon , icon2 + x.daily.data[1].icon......icon8 + x.daily.data[7].icon.. but the icons wont show up..
divs.appendChild(canv)
}
最佳答案
我创建了一个新循环
for(y=0;y<8;y++){
skycons.set('icons'+(y+1), Skycons = x.daily.data[y].icon)
}
并从另一个循环中删除该东西