for(let feature of features){
$("#menuList").append("<li></li>");
}
$("#menuList li").on('click', function(ev){
// I need a reference to the original feature object here
});
What is the best way to get a reference to the original feature-object within the click handler (without passing some ID as a data tag and iterating over the list again)?
Ideally, I could do something like
for(let feature of features){
$("#menuList").append("<li></li>").on('click', function(feature){ //do something with the feature object });
}
But this does not work.
featureorfeatureshere? Are you appending anything tolifrom it?libut I really need to pass the object to the click handler, that's the problem$.appendTolooks to be another function that will return a reference to the just appended element (not a ref to the parent element like$.append()does), and you'll be able to set that.on('click'directly, I suppose.