简体   繁体   中英

How would I get options from object?

This is the structure:

e {options: {…}, _latlng: M, _radius: 10, _initHooksCalled: true}
options:
id: "https://example.com/travel/weekend-a-barcelona/"
__proto__: Object
__parent: e {options: {…}, _latlng: M, _group: e, _zoom: 6, _markers: Array(2), …}
_events: {click: Array(1), dragstart: Array(1), move: Array(1), dragend: Array(1)}
_initHooksCalled: true
_latlng: M {lat: 41.39483307195536, lng: 2.148767850000013}
_leaflet_id: 495
_radius: 10
__proto__: e

I need to get the link id: "https://example.com/travel/weekend-a-barcelona/"

I tried

 circle.on('click', function (e) {
   var circleLink = e.target.options();
   alert(circleLink);

But I get Uncaught TypeError: e.target.options is not a function

You could access nested objects like below. Basically you're getting the value of options using e.options , and then to get the link, you have to get the value of options (which we previously found out was e.options ) and add .id to the end. You end up with e.options.id

 const e = { options: { id: "https://example.com/travel/weekend-a-barcelona/" } }; console.log(e.options.id); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM