Y
Y
Yaroslav2018-09-04 14:42:41
JavaScript
Yaroslav, 2018-09-04 14:42:41

How to disable the selection of values ​​that are not included in the group?

there is an array of objects whose properties are arrays of objects:

const data = [
  {
    id: 1,
    items: [
      {
        group: "a",
        name: "name",
        checked: false
      },
      {
        group: "b",
        name: "name",
        checked: false
      }
    ]
  },
  {
    id: 2,
    items: [
      {
        group: "c",
        name: "name",
        checked: false
      },
      {
        group: "b",
        name: "name",
        checked: false
      }
    ]
  }
];

const groups = {
  ab: ["a", "b"],
  c: ["c"]
}

How to disable the selection of objects from group "c" (you can't set checked = true) when objects from group "ab" are selected and vice versa? Tell me the algorithm of actions, please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-09-04
@CubaJas

We go around all the elements, check: if the checked element and its group at the same time differ from the group of the element of interest to us, we prohibit the selection. Somehow so .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question