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”
请重新检查功能数组。请使用脚本控制台。