我的反应应用程序出现问题,我无法在skycons两次显示相同的图标。
我发现this post有同样的问题。但是 - 当我复制解决方案时,我收到错误bundle.js:130 Uncaught ReferenceError: e is not defined
供参考,这是我的代码
componentDidMount() {
this.serverRequest = $.get(this.props.source, function (result) {
this.setState({
forecast: result.currently,
daily: result.daily.data
});
var icons = new Skycons({
"color": "#666"
}),
list = [
"clear-day", "clear-night", "partly-cloudy-day",
"partly-cloudy-night", "cloudy", "rain", "sleet", "snow", "wind",
"fog"
],
i;
for (i = list.length; i--;) {
var weatherType = list[i],
elements = document.getElementsByClassName(weatherType);
for (e = elements.length; e--;) {
icons.set(elements[e], weatherType);
}
}
icons.play();
}.bind(this));
}
我已尝试在代码中声明e
个不同的位置,但即使代码已复制/粘贴,它也不适用于我
显然错误在这里for (e = elements.length; e--;) {
答案 0 :(得分:0)
我想你想要这个:
for (i = list.length; i--;) {
var weatherType = list[i],
elements = document.getElementsByClassName(weatherType);
for (var e = elements.length; e > 0; e--) {
icons.set(elements[e], weatherType);
}
}