简体   繁体   中英

how can I show the information of a list object

I have books categorized by the category attribute, how can I get the description value of the books to display on a screen?

already tried using values ​​() and the keys ()

{1: Array(2), 2: Array(1), 4: Array(1), 9: Array(1)}

1: Array(2)
0: {id: 1, description: "teste", category: 1}
1: {id: 73, description: "basica tb", category: 1}
length: 2
__proto__: Array(0)
2: Array(1)
0: {id: 3, description: "Teoria das ideias", category: 2}
length: 1
__proto__: Array(0)
4: Array(1)
0: {id: 5, description: "Mr with research computer.", category: 4}
length: 1
__proto__: Array(0)
9: Array(1)
0: {id: 10, description: "Vote drug thus no.", category: 9}
length: 1
__proto__: Array(0)
__proto__: Object

i need return the title of objects bibliographies

This code should work. Use Object.keys and reduce , to map over every value and return the description:

 const data = { 1: [ {id: 1, description: "teste", category: 1}, {id: 73, description: "basica tb", category: 1} ], 2: [ {id: 3, description: "Teoria das ideias", category: 2} ], 4: [ {id: 5, description: "Mr with research computer.", category: 4} ], 9: [ {id: 10, description: "Vote drug thus no.", category: 9} ] } const getDescription = data => Object.keys(data).reduce((a, key) => ({...a, [key]: data[key].map(o => o.description)}), {}) console.log(getDescription(data))

Hi Gustavo I'm not quite sure what you want but i think you want to render a list of your object. There are so many ways to do it but im going to show you the most easy way by using javascript higher-order function map .This higher-order function let's you to loop through your array.

Simple Instance:

import React from 'react';

const List = () => {
      const data = [{
      name: 'Joe',
      age: '16'
      }]
      return (
      {data.map(data => <li key={data.age}>{data.name}</li>)}
)
}

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