如何通过单击标记来更新标记弹出窗口?

How can I update the marker popup by click the marker?

我试图通过点击事件更新弹出窗口,但它似乎不起作用。我看过官网的demo。他们通过更新 geojson 数据来更新,我认为这可能效率不高。

markers.on('click', function(e){
    console.log('marker-onClick', e);
    e.layer._popup._content = 'hello';
})

正确的方法是使用L.MarkersetPopupContent方法:

Sets an HTML content of the popup of this marker.

http://leafletjs.com/reference.html#marker-setpopupcontent

markers.on('click', function (e) {
    e.layer.setPopupContent(...);
});