score:1
You can loop through them like this:
{this.state.jData && Object.keys(this.state.jData).map(key => (
<>
{this.state.jData[key].map(data => (
<div className="cell large-3">
<h3>{data.name}</h3>
</div>
))}
</>
))}
score:0
You are trying to iterate an object. Hence you cannot directly use "map" as an option. You can try as below to iterate:
var jData = {
"selva": [{
"cus_id": "1",
"name": "selva",
"loc_name": "chennai",
"loc_phone": "986478393",
"loc_email": "selva@gmail.com"
},
{
"cus_id": "1",
"name": "selva",
"loc_name": "Trichy",
"loc_phone": "123456789",
"loc_email": "surya@gmail.com"
}
],
"ram": [{
"cus_id": "3",
"name": "ram",
"loc_name": "tnager",
"loc_phone": "45654345",
"loc_email": "ram@gmail.com"
}],
"Sam": [{
"cus_id": "4",
"name": "Sam",
"loc_name": "chrompet",
"loc_phone": "234545634",
"loc_email": "sam@gmail.com"
},
{
"cus_id": "4",
"name": "Sam",
"loc_name": "mount",
"loc_phone": "234545634",
"loc_email": "sam@gmail.com"
},
{
"cus_id": "4",
"name": "Sam",
"loc_name": "adambakkam",
"loc_phone": "45654345",
"loc_email": "sam@gmail.com"
}
]
};
Object.keys(jData).map(val => {
jData[val].map(cusData => {
//Print your data here
console.log(cusData['loc_name']);
console.log(cusData['loc_phone']);
});
});
This is an idea to iterate your object. But please make sure your json is not too large. Otherwise it'll hit your performance and then you might have to find alternative way to print your data.
score:0
Here you go
export default function DetailTable({data}) {
return (
<div className="grid-x small-up-12">
<BuildDetailTable data={data} />
</div>
);
}
const BuildDetailTable = ({ data }) => {
const result = [];
for (const [key, value] of Object.entries(data)) {
result.push(
<div className="cell">
<div className="callout">
<div className="grid-x">
<div className="cell large-3">
<h3>{key}</h3>
<BuildDetailRow data={value} />
</div>
</div>
</div>
</div>
);
}
return result;
};
const BuildDetailRow = ({ data }) => {
const result = [];
for (const item of data) {
result.push(
<div className="cell large-9">
<div className="table-break">
<div className="grid-x">
<div className="cell medium-4">
<div className="grid-x">
<div className="cell large-12">
<span>Name: {item.loc_name}</span>
</div>
</div>
</div>
<div className="cell medium-3">
<span>Phone: {item.loc_phone}</span>
</div>
<div className="cell medium-3">
<span>Email: {item.loc_email}</span>
</div>
<div className="cell medium-2">
<input
type="button"
className="label label-button float-right"
value="Edit"
/>
</div>
</div>
</div>
</div>
);
}
return result;
};
Is you pass the api data to DetailTable
component, it will render the desired result
<DetailTable data={data from api}/>
The output I get is:
Source: stackoverflow.com
Related Query
- how to loop throgh array of object from axios json respone in react js and set them in div?
- How to set data in react typescript array of object from axios response
- In React Hooks. How to set state to a random number and use that to display a string from an array
- How to make a react table whose rows and columns come from a JSON object
- How to find most recent date from an array of object then add new field and return array in react
- How to loop an object that is inside an array and is inside an object? React
- Using data from API JSON object using Axios and React
- How to fetch Json nested and Make it Array of object in React
- React map object and embedded object from JSON and convert to single array for state
- How to pass a json array that comes from backend to child component using props and react hooks?
- How can i post array of object using axios formik and react js
- How to parse a JSON object from an external file in React using .map() in ES6 and a loop?
- How do I return a JSON array in React from a local file and have it map through all of my items?
- React - How to access single value from array of array json object
- How to render an object from an array in MongoDB and react
- How to convert a React array to a JSON object with same key and value?
- How to set a JSON object from local.storage using setState with React Hooks
- How to set defaultValue of a radioGroup from a nested Array object in React state?
- How to retrieve different type of data from JSON object array and play with it?
- How can I delete an entire json object from an array of json objects and write it out to file?
- How to loop through an array and display data within the object of that array, in react and javascript
- Getting data from a JSON array and setting states based on the data using loop in React
- How to loop over an object in an array of JSON data and check if their name contains a certain string?
- How can i React ( get axios from Json and ReRandering my page)
- How to send array of objects data from child component to parent component and store in the parent object using react hooks?
- How to use for loop in react so I can loop over two array and return the object in second array if both match
- How to set state of response from axios in react
- How to set React component state and props from browser
- React.js: loading JSON data with Fetch API and props from object array
- How to delete object from array using object property - React
More Query from same tag
- why array like syntax is used when dynamically setting react state
- State is returning new state without touching the state REACT/REDUX
- React: how to make an input only as wide as the amount of text provided?
- Tpyography breaks into second line in toolbar with grid
- React hook not updating after the API call
- How to clean up the useEffect function?
- redux-promise: Uncaught TypeError: middleware is not a function
- AWS Coginto API , Forgot Password Action not raising InvalidParameterException even if neither a verified phone number nor a verified email exists
- TypeError: Cannot read property 'map' of undefined - Shopping cart in reactjs
- not getting image using Axios in react
- Getting req.headers is undefined when trying to read from req object in NextJS
- How to fix Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object
- Detect the url (on reactjs) to hide an element on the page
- Why are my conditional checks are failing and firing a function?
- Unable to display bootstrap panels in react js
- Can not excess the value of a variable outside the class
- how to get the values that were sent from axios.post in the backend
- React 16.3 Context API -- Provider/Consumer issues
- Filtering an array: how to order the filters
- getting error in image tag in react js tsx file
- Why do i get : Must use destructuring state assignment?
- React-router multiple component onEnter in case of auth?
- React - how to pass component and props to children component and make that component use that props
- Switch statement not working within JSX (React.js)
- "Unexpected token" will trying react-datepicker
- Unable to deploy to Heroku, no changes were made
- Victory Charts background grid
- forEach returning some jsx in a function how should this be done?
- addEventListener inside useLayoutEffect: the event listener is added multiple times
- Redux dispatch function and TypeScript