Javascript 有人能认出丢失的花括号吗
我束手无策。我已经花了大约3个小时修改我的代码,试图找出这个缺少的花括号。每次我想我已经修好了,它就会在另一条线上出现一个新的缺少的花括号。请帮助我,我想哭 代码如下:Javascript 有人能认出丢失的花括号吗,javascript,syntax-error,curly-braces,Javascript,Syntax Error,Curly Braces,我束手无策。我已经花了大约3个小时修改我的代码,试图找出这个缺少的花括号。每次我想我已经修好了,它就会在另一条线上出现一个新的缺少的花括号。请帮助我,我想哭 代码如下: function addCTHValue() { $.getJSON("https://api.myjson.com/bins/nh71g") .done(function(data) { }); function processCTHValueData(data) {
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.geoJsondata,{但我认为我的大脑在这一点上挡住了花括号的视线。请帮助?对花括号表示新的作用域,或者一个对象文字,因为这是JavaScript
请看以下代码:
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
}}
注意:在这个代码块中,直接从函数addCTHValue往下走,你不会看到一个大括号。函数在哪里结束?显然,ProcessCthValue数据现在实际上包含在addCTHValue中-它应该是吗?如果你能回答这些问题,放置大括号是一项非常简单的任务,但是如果你不能,我们也不能,因此无法为您修复代码。正如@joel-m所说,代码很混乱,看起来您以前甚至没有测试过它,据我所知,有很多错误,但看起来您总是在使用{} addTomap在GeoJS调用的调用之外。现在应该可以了
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);
});
}
.done函数正在立即关闭?.donefunctiondata{};processCTHValueData只在addCTHValue中定义,您稍后会尝试调用它。我认为,对于范围和括号的用途存在根本性的理解不足,如果attribute='CTH Value'应该是,如果attribute='CTH Value'或===如果您想要严格的相等,则不必粗鲁,Joel M我是一个完全的初学者Javascript和我试着遵循一个教程。很抱歉,我想是别人写的。我不是想表现得粗鲁。谢谢你的帮助。我对Javascript非常陌生,我一直在遵循一个教程,但我想我做得很差。我如何测试代码?我真的不知道如何与web控制台通信,所以可能这就是我为什么这么做的原因拉格林。我刚刚得到一个新的错误:intermediate value.on不是一个函数,你知道这意味着什么吗?我不知道processCTHValueDatadata是否应该放在addCTHValue中。我假设是这样。我正在尝试遵循本教程:但我真的很挣扎。即使复制了其他一些解决方案,我仍然收到一条错误消息说我缺少一个花括号。@Sophgis正在看那个教程,我可以看到哪些部分是直接复制的,但不知怎么的,你的复制是不完整的……比如函数CTHValueSymbols由于某种原因复制时没有最后一行和花括号,我甚至没有看到$.getJSONhttps://api.myjson.com/bins/nh71g 在某一时刻处于任何功能中我想你需要遵循一个基本的javascript教程,在试图简单地按顺序复制每个代码块并使其工作之前,尝试真正理解代码在做什么。我没有复制所有代码块,因为我不想使用时间滑块。我找不到一个不使用插件的基本比例圆映射n创建地图。
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);
});
}
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)
});}