Javascript _传单id返回onEachFeature函数中未定义的内容

Javascript _传单id返回onEachFeature函数中未定义的内容,javascript,leaflet,geojson,Javascript,Leaflet,Geojson,我试图通过功能onEachFeature访问每个功能的\u传单\u id。当与以下内容一起使用时,它总是返回未定义的: function onEachFeature(feature, layer) { console.log(layer._leaflet_id); } 使用以下工具时,我获得了正确的\u传单\u id: sampleGeoJSON.eachLayer(function(layer) { console.log(layer._leaflet_id); }) \u传

我试图通过
功能onEachFeature
访问每个
功能的
\u传单\u id
。当与以下内容一起使用时,它总是返回未定义的

function onEachFeature(feature, layer) {
   console.log(layer._leaflet_id);
}
使用以下工具时,我获得了正确的
\u传单\u id

sampleGeoJSON.eachLayer(function(layer) {
    console.log(layer._leaflet_id);
})

\u传单\u id
是传单库在需要时设置的内部标识符

当您第一次构建层时(我想是通过
L.geoJSON
factory?),它们可能还没有那个标识符

如果要强制传单指定标识符(如果尚未设置标识符),请使用(或快捷方式
L.stamp