JS新手。该声明似乎不起作用:
if (kcdfp_parcel[i].InActive == 0)
数据是带有变量" kcdfp_parcel"的geoJSON文件。
这是文件的一小部分:
kcdfp_parcel = [{ "输入":" FeatureCollection", " crs":{" type":" name"," properties":{" name":&#34 ;瓮:OGC:DEF:CRS:OGC:1.3:CRS84" },
"features": [
{ "type": "Feature", "properties": { "MAJOR": "000440", "MINOR": "0018", "PIN": "0004400018", "FarmID": 3101.000000, "LastName": "Codiga", "Acres": 62.940000, "Cooperativ": null, "InActive": 0, "ParcelNumb": "0004400018", "Shape_Leng": 0.024319, "Shape_Area": 0.000030 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -122.254601971999989,
我是否正确引用了LastName字段(例如,我是否需要使用kcdfp_parcel.features.InActive)?
或者,我的IF声明错了吗?
答案 0 :(得分:0)
应该可以参考" InActive"通过kcdfp_parcel.features[some_index].properties.InActive
,如下例所示。通过console.log
在浏览器控制台上输出如下所示:
功能索引0的属性InActive为0,ParcelNumb为 0004400018
功能索引1具有属性InActive为0和ParcelNumb 0006400009
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<body>
<h1>Check your browser console...</h1>
</body>
<script type="text/javascript">
var kcdfp_parcel = {
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "…"
}
},
"features": [
{
"type": "Feature",
"properties": {
"InActive": 0,
"ParcelNumb": "0004400018"
},
"geometry": {
"type": "Polygon",
"coordinates": [ [ [ -122.254601971999989, 47.364317413000038 ], [ -122.254231611999955, 47.364320569000029 ] ] ]
}
},
{
"type": "Feature",
"properties": {
"InActive": 0,
"ParcelNumb": "0006400009"
},
"geometry": {
"type": "MultiPolygon",
"coordinates": [ [ [ -122.059132819999945, 47.197189012000081 ], [ -122.059119953999982, 47.197182407000071 ] ] ]
}
}
]
};
for (var i = 0; i < kcdfp_parcel.features.length; i++) {
console.log("Features index " + i + " has property InActive of " + kcdfp_parcel.features[i].properties.InActive +
" and ParcelNumb of " + kcdfp_parcel.features[i].properties.ParcelNumb);
}
</script>
</html>