Я пытаюсь создать ключи для объектов, которые добавляются в массив.
widgets [
"hats": {widget},
"shirts": {widget},
...
...
]
Когда я регистрирую виджеты ниже, в консоли ничего не возвращается или объект / виджет не добавляется в массив виджетов.
let widgets = [];
$(document).on("change",'select.filter-select, .filter-checkbox input', function(e) {
const widget = {};
const $this = $(this);
if ( $this.hasClass('checkbox') ) {
widget.type = $this.data('type');
widget.blueprint = $this.data('blueprint');
widget.handle = $this.data('handle');
widget.url = $this.data('url');
}
else{
const option = $('option:selected', this);
widget.type = option.parent().data('type');
widget.blueprint = option.parent().data('blueprint');
widget.handle = option.data('handle');
widget.url = option.data('url');
}
if ( widgets.length > 0 ) {
$.each(widgets, function (key,value) {
if (!widgets[widget.handle]) {
widgets[widget.handle].push(widget);
}
});
}
else {
widgets[widget.handle].push(widget);
}
console.log(widgets + "\n\n");
});