[
{
"device_type_id": 1,
"children": [
{
"name": "MacOS",
"id": 4,
"children": [
{
"name": "OS X 10",
"id": 35
}
]
},
{
"name": "Windows",
"id": 3,
"children": [
{
"name": "Windows XP",
"id": 28,
"key": "1_28"
},
{
"name": "Windows Vista",
"id": 29,
"key": "1_29"
}
],
"key": "0.09045594089569153-1"
},
{
"name": "Linux",
"id": 5,
"key": "1_5"
},
{
"name": "Other",
"id": 6,
"key": "1_6"
}
],
"key": 1
},
{
"device_type_id": 2,
"children": [
{
"name": "Android",
"id": 1,
"children": [
{
"name": "Android 14",
"id": 17,
"key": "2_17"
},
{
"name": "Other",
"id": 18,
"key": "2_18"
}
],
"key": "0.6381681047050869-0"
},
{
"name": "Other",
"id": 6,
"key": "2_6"
}
],
"key": 2
}
]
disabledOs() {
this.form.os.map(with_device => {
const isDisabled = !this.form.device_types.includes(
with_device.device_type_id
)
with_device.disabled = isDisabled
if (!with_device?.children) return
with_device.children.map(el => {
el.disabled = isDisabled
if (!('device_type_id' in el)) {
'children' in el
? el.children.map(child => (child.disabled = isDisabled))
: (el.disabled = isDisabled)
}
})
})
return this.form.os
}
}
disabledOs
свойство children
у элементов не меняется, т. к. метод map
не мутирует переданный в него массив, а возвращает новый.disabledOs() {
const modifyElement = (el, isDisabled) => {
return {
...el,
...(el.children && {
children: el.children.map(c => modifyElement(c, isDisabled)),
}),
disabled: isDisabled,
};
};
return this.form.os.map(el => {
const isDisabled = !this.form.device_types.includes(el.device_type_id);
return modifyElement(el, isDisabled);
});
};