ниже приведен код:
Код: Выделить всё
if (childItem) {
const childButton = $('', {
text: childItem.section_name,
'id': childItem.id,
'class': 'button-location-style child-section',
click: function() {
var index = ids.indexOf(childItem.id);
if (index > -1) {
// Unselect the child
ids.splice(index, 1);
$(this).removeClass("changedBackground");
// Enable the parent section when the child is unselected
$(`#${parentId}`).removeClass('disabled');
} else {
// Select the child
ids.push(childItem.id);
$(this).addClass("changedBackground");
// Disable the parent section when the child is selected
$(`#${parentId}`).addClass('disabled');
}
// Update the section ID input field with the selected IDs
$('#SectionId').attr('value', ids.join(','));
}
});
// Append the child button to the container
childContainer.append(childButton);
- Должен быть включен только родительский раздел когда все дочерние разделы
не выбраны. - Родительский элемент ведет себя не так, как ожидалось. После выбора нескольких
дочерних разделов и отмены выбора одного родительский элемент остается отключенным, хотя
не следует выбирать все дочерние разделы.
- Я проверял массив идентификаторов, когда дочерний элемент выбран или не выбран,
но родительский элемент все еще не включен, когда все дочерние элементы не выбраны.
Подробнее здесь: https://stackoverflow.com/questions/793 ... -selection