V
V
Vanya Huk2018-05-20 04:11:03
React
Vanya Huk, 2018-05-20 04:11:03

How to properly design a react application ( see details )?

There is such a select with an optiongroup
5b00c92cbc677176067652.png
in which you can select both 1 select and the whole group.
after clicking on the select, its value gets into the array,
models : []
but what to do with the whole group?
here is the structure of the array which is in the select

[
    {
      value: 495,
      label: '1 Series',
      children: [
        {
          value: 10920,
          label: '116'
        },
        {
          value: 10921,
          label: '118'
        },
        {
          value: 10922,
          label: '120'
        },
        {
          value: 10923,
          label: '125'
        },
        {
          value: 10924,
          label: '135'
        }
      ]
    },
    {
      value: 10925,
      label: '1 Series М'
    }
]

you need to somehow take all the values ​​of childrens when the whole group is selected, and only the value of value when only 1 element is selected and push it into the models array , but you also need to take into account the fact that select will be cloned for other car brands

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-05-20
@alexr64

Pseudocode. I think you get the idea.

onclick(item)
{
 if(item.children != null)
     {
     foreach(ch_item in item.children)
          {
          add_to_selected(ch_item)
          }
     } else
     {
     add_to_selected(item)
     }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question