score:1
when a feature is created with the new feature({})
constructor, it does not look quite like the property-object put into the constructor. the properties you passed into the new feature will be stored under values
of that feature.
the full properties of an ol-feature can be accessed via feature.getproperties()
single values can be accessed via feature.get(key)
in your example, in data.map
you named the first parameter name
, which actually is the feature. this is a little bit confusing, i think feature
or something similar would be a clearer variable name.
to get that features value, call name.get('name')
(or feature.get('name')
if you decide to rename the parameter)
also, the second argument of array.map
is the index in the array, so in your case this will give you 0
and 1
, which is fine if these are the values you want. if you want to get the id you can access these values by calling name.get('id')
or feature.get('id')
(see above). i guess i should mention the openlayers-functions feature.setid()
and feature.getid()
, just for completions sake.
tl;dr
try name.get('name')
instead of name.name
and check the results
score:1
use this instead (remove double-quotations):
new feature({ id: 101, name: "abc" }),
new feature({ id: 102, name: "xyz" })
Source: stackoverflow.com
Related Query
- looping through an open layer feature object array
- Looping through two object arrays to push matching values to a new array doesn't work in React but does in JS Fiddle
- Looping through an array of objects and mapping each object them to a single template object
- Looping through array of objects and return the key and value for each object
- React native mapping through array with object childs - working different as in react web?
- Iterate through a nested json object array in the render (ReactJS)
- Looping through a JSON array with ReactJS, but not understanding how the code actually works
- Fetch request in React: How do I Map through JSON array of object inside of array of objects?
- Loop through array of objects, check for a matching parameter and add the matching object to new array
- Display key value pairs from looping through an array of objects
- Array of object iterating through map to render a component key not updating in props
- Loop through Array of object with the same data on some object and get it displayed once
- React, nothing is shown after looping through an array of data with map method
- How to map through an object with array of object
- How to iterate through the array inside json object
- How do I map an through an array of objects and display each object individually? I want each pizza order to show
- Loop through array of object and get values
- How can loop through array of JSON Object to find property value that includes user input characters
- How to loop through complex object or array of object
- Looping through nested data and displaying object properties and values
- How can I break through React maps to display object that has two values one with an array other with string or number(result)
- React: Adding an object to an array in state through input fields
- Loop through array of objects and return object keys
- Map through array of arrays, to find id and change object
- Map through array that includes object
- filter through array values inside object
- Fetching URL data and looping through it to push it to a component's state array - ReactJS
- How to update an array in React using Hooks. Not adding new elements just looping through a list
- I need to dispatch action inside a saga by looping through an array
- React exclude one object from array while mapping through the component
More Query from same tag
- React - html tags inside svg
- React custom synthetic event
- Write to a text or JSON file - react - node
- How to use multiple fetchs with POST, DELETE and then GET requests
- can I use array as depenedency in useEffect() in react?
- React Does Not Creat App Mistake. How Do I Solve?
- change contents of a table by taking data from another table in react
- Uncaught Error: Configuration must contain `projectId`( when using environment variable )
- Navigating From One local Host to another in react js
- How to display three post photo div at the bottom of the page using Reactjs and Css
- Redux form not getting re-rendered
- Why is an array that is passed correctly via props returning undefined?
- React Hooks changing state of an array inside of asycn function after useEffect call
- Why does React Hooks Axios API call return twice?
- Getting TypeScript compile error when attempting prop drilling of state objects in Ionic/React
- How to scroll to index in infinite list with react-virtualized
- How to make babel-plugin-transform-imports work
- Stateless Functional Component - React
- How to mock all files in a folder in jest
- Argument of type '{ identifier: string; }' is not assignable to parameter of type 'ConcatArray<never>'
- Pass props to higher-order stateless functional React component
- How to show correct displayName in react-scripts-ts projects when using Styled Components
- why axios convert http request to https in reactjs
- In React Router v6, how to check form is dirty before leaving page/route
- VERY High number of reads in Firestore database in my React Project
- How to fix this warning: "React Hook useEffect has a missing dependency: 'history'"?
- React JSX boolean condition causing sonar cognitive complexity
- ImmutableJS - update value in a List
- My reducer returns undefined as if it wasn't added into combineReducers, but it is
- Embedding clutch.co widget to Gatsby.js website