【发布时间】:2019-12-17 17:31:21
【问题描述】:
我束手无策。我一直在修改我的代码 3 个小时,现在试图解决这个丢失的大括号。每次我认为我已经修复它时,它都会在不同的行上出现一个新的缺失花括号。请帮帮我,我想哭。
代码如下:
function addCTHValue() {
$.getJSON("https://api.myjson.com/bins/nh71g")
.done(function(data) {
});
function processCTHValueData(data) {
var min = Infinity;
var max = -Infinity;
for (var feature in data.features) {
var properties = data.features[feature].properties;
for (var attribute in properties) {
if ( attribute = 'CTH Value' )
{
if (properties[attribute] < min) {
min = properties[attribute];
}
if (properties[attribute] > max) {
max = properties[attribute];
}
}
}}
return {
min : min,
max : max
}}
function CTHValueSymbols(data) {
CTHValueCountries = L.geoJson(data, {
pointToLayer: function(feature, latlng) {
return L.circleMarker(latlng, {
fillColor: "#501e65",
weight: 2,
fillOpacity: 0.5,
radius: feature.properties["CTH Value"]/100
})}
.on({
mouseover: function(e) {
this.openPopup();
this.setStyle({fillColor: 'green'});
},
mouseout: function(e) {
this.closePopup();
this.setStyle({fillColor: '#501e65'});
}
});
}
}).addTo(map);
function calcCTHValueRadius(attributeValue) {
var scaleFactor = 0.01;
var area = attributeValue * scaleFactor;
return Math.sqrt(area/Math.PI);
}
$.getJSON("https://api.myjson.com/bins/nh71g").done(function(data) {
var info = processCTHValueData(data);
CTHValueSymbols(data)
});
}
据称缺少的大括号位于以下行:CTHValueCountries = L.geoJson(data, { 但是我认为我的大脑此时已经挡住了大括号的视线。请帮忙?
【问题讨论】:
-
.done()函数正在立即关闭?.done(function(data) { }); -
processCTHValueData仅在addCTHValue()中定义,您稍后会尝试调用它。我认为人们对范围和括号的用途缺乏了解 -
if ( attribute = 'CTH Value' )应该是if ( attribute == 'CTH Value' )(如果你想要严格相等,则应该是===) -
没有必要粗鲁 Joel M 我是 Javascript 的初学者,我正在尝试学习教程
-
lol 对不起,我以为是别人写的。我不是想无礼。
标签: javascript syntax-error curly-braces