Z
Z
zlobniyPingvin2019-11-13 15:49:55
JavaScript
zlobniyPingvin, 2019-11-13 15:49:55

How to display JSON data in react-native without a list?

Good afternoon. I'm learning how to develop an application in react native, I ran into a problem with displaying data.
json coming from server side

[
  {
    "cell_name": "112185",
    "id": "000000005",
    "pallets": [
      {
        "id": "000000016",
        "items": [
          {
            "product_info": {
              "name": "Ванилин 1,5 гр",
              "unit_info": {
                "name": "шт"
              },
            },
            "count": 100
          },
          {
            "document_uid": "a520c7b5-e990-11e9-ab43-005056ab6dbf",
            "product_info": {
              "name": "Огурцы конс. 0,72 1/12",
              "unit_info": {
                "name": "шт"
              },
            },
            "count": 23
          },
          {
            "document_uid": "a520c7b5-e990-11e9-ab43-005056ab6dbf",
            "product_info": {
              "name": "Опята конс. 370 г. 1/12",
              "unit_info": {
                "name": "шт"
              },
            },
            "count": 15
          }
        ]
      }
    ]
  }
]

I need to display information on the screen.
I tried to display in this way, but I failed - nothing is displayed.
return (
        <PageView
             ...
        >
            <View>

                    { cells.map((cell, cell_i) => {
                        const cell_name = cell.name == '' ? 'Без ячейки' : cell.name;
                        return (<Text key={cell_i}>Ячейка {cell_name}</Text> &&
                            ( for (i in cell.pallets) {
                                const pallet = cell.pallets[i];
                                const pallet_name = pallet.id == '' ? 'Без паллеты' : pallet.id;
                                return (<Text h2 key={cell_i+'.'+pallet_i}>Паллета {pallet_name}</Text> &&
                                    ( for(j in pallet.items) {
                                        const item = pallet.items[j];
                                        return (<Text key={cell_i+'.'+pallet_i+'.'+item_i}>{item.product_info.name} {item.count} {item.product_info.unit_info.name}</Text>);
                                    })
                                )
                            })
                       )
                    })}
            </View>
        </PageView>
        )

Perhaps someone will suggest an idea how to properly display such a structure?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-11-13
@dimoff66

{ cells.map((cell, cell_i) => {
  const cell_name = cell.name == '' ? 'Без ячейки' : cell.name;
  return <>
    <Text key={cell_i}>Ячейка {cell_name}</Text> 
    {cell.pallets.map(pallet => {...})} // троеточие замените на текст вывода
  </>
})}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question