Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript/OpenLayers匹配_Javascript_Openlayers_Matching - Fatal编程技术网

Javascript/OpenLayers匹配

Javascript/OpenLayers匹配,javascript,openlayers,matching,Javascript,Openlayers,Matching,我曾经使用以下方法筛选我的功能: for (var i=0; i<features.length; i++) { if (features[i].attributes.color == 'blue') . . 我得到这个错误: Cannot call method 'match' of undefined 看起来,有些功能没有设置颜色属性。运行,例如: for (var i=0; i<features.length; i++) console.log(t

我曾经使用以下方法筛选我的功能:

for (var i=0; i<features.length; i++) 
 { 
 if (features[i].attributes.color == 'blue') 
. 
. 
我得到这个错误:

Cannot call method 'match' of undefined 

看起来,有些功能没有设置颜色属性。运行,例如:

for (var i=0; i<features.length; i++) 
    console.log(typeof features[i].attributes.color);
所以您应该先测试是否设置了颜色属性,然后再测试:

for (var i=0; i<features.length; i++) 
    if (features[i].attributes.color && features[i].attributes.color == 'blue') ...

for(var i=0;i某些功能似乎没有设置颜色属性。例如,运行:

for (var i=0; i<features.length; i++) 
    console.log(typeof features[i].attributes.color);
所以您应该先测试是否设置了颜色属性,然后再测试:

for (var i=0; i<features.length; i++) 
    if (features[i].attributes.color && features[i].attributes.color == 'blue') ...

for(var i=0;iDid您是否检查
功能[i]
是否存在?是的..如果我使用
(功能[i].attributes.color='blue')
仍然获得
无法调用未定义的方法“toString”
重新检查功能数组。使用脚本控制台。是否检查
功能[i]
存在?是..如果我使用
(功能[i].attributes.color=='blue')
仍然获得
无法调用未定义的方法“toString”
请重新检查功能数组。请使用脚本控制台。