$('.item').on('mouseover', '.dot', function({ delegateTarget: t }) {
$('.thumb-target', t).attr('src', $(this).data('img'));
$('.dot', t).removeClass('select').filter(this).addClass('select');
});
document.querySelectorAll('.item').forEach(n => {
n.addEventListener('mouseover', onMouseOver);
});
function onMouseOver({ target: t, currentTarget: ct }) {
const dot = t.closest('.dot');
if (dot) {
ct.querySelector('.thumb-target').src = dot.dataset.img;
ct.querySelectorAll('.dot').forEach(n => {
n.classList.toggle('select', n === dot);
});
}
}
.frame {
на .slider /deep/ .frame {
.mounted() { for (let i = 0; i < 3; i++) { let frame = document.createElement("div"); frame.classList.add("frame"); //класс присваивается но стили не применяются this.$refs.slider.appendChild(frame); } },
const sum = (...arr) => arr
.flatMap(Object.entries)
.reduce((acc, [ k, v ]) => (
acc[k] = (acc[k] ?? 0) + v,
acc
), {});
function sum() {
const result = {};
for (const n of arguments) {
for (const k in n) {
if (n.hasOwnProperty(k)) {
if (!result.hasOwnProperty(k)) {
result[k] = 0;
}
result[k] += n[k];
}
}
}
return result;
}
const obj = sum(obj1, obj2);
. Визуал jsx элемента, как и вопросы форматирования времени и даты не так важны, как важно просто разобраться с возможной последовательностью действий, как все это описать.
arr.map(n => {
const start = форматированное значение n.start_at;
const end = форматированное значение n.end_at;
return <span>{start} - {end}</span>;
})
const container = document.querySelector('#element');
const itemSelector = '.someclass';
function onClick(e) {
e.preventDefault();
console.log(e.target.closest('li').dataset.id);
}
container.querySelectorAll(itemSelector).forEach(n => {
n.addEventListener('click', onClick);
});
container.addEventListener('click', e => {
const item = e.target.closest(itemSelector);
if (item) {
onClick(e);
}
});
По одному работает, если отметить оба, то "Error in v-on handler: "TypeError: Cannot convert undefined or null to object"
validations() {
return {
life: this.property ? {} : { required: v => v },
property: this.life ? {} : { required: v => v },
};
},
<div>STATUS: {{ $v.$invalid ? 'ЖОПА' : 'OK' }}</div>
function sort(arr) {
const obj = Object.fromEntries(arr.map(n => [ n.parent, n ]));
const sorted = [];
for (let item = obj['null']; item; item = obj[item.id]) {
sorted.push(item);
}
return sorted;
}
function sort(arr, parent = null) {
const item = arr.find(n => n.parent === parent);
return item
? [ item, ...sort(arr, item.id) ]
: [];
}
const newStr = new Date(str.split(' GMT', 1)[0])
.toLocaleDateString('ru-RU')
.split('.')
.reverse()
.join(', ');
const formatDateStr = function(str) {
const [ , month, day, year ] = str.match(/(\S+) (\d+) (\d+)/);
return [ year, this[month], day.padStart(2, 0) ].join(', ');
}.bind(Object.fromEntries(Array.from({ length: 12 }, (_, i) => [
new Date(0, i).toLocaleString('en', { month: 'short' }),
`${i + 1}`.padStart(2, 0)
])));
const newStr = formatDateStr(str);
const columns = [ '#', ...new Set(persons.flatMap(Object.keys)) ];
document.body.insertAdjacentHTML('beforeend', `
<table>
<thead>
<tr>${columns.map(col => `
<th>${col}</th>`).join('')}
</tr>
</thead>
<tbody>${persons.map((person, i) => `
<tr>${columns.map((col, j) => `
<td>${j ? person[col] ?? '-' : i}</td>`).join('')}
</tr>`).join('')}
</tbody>
</table>
`);
const table = document.createElement('table');
table.createTHead().insertRow().append(...columns.reduce((acc, col) => (
(acc[acc.length] = document.createElement('th')).textContent = col,
acc
), []));
persons.forEach(function(person, i) {
const tr = this.insertRow();
columns.forEach((col, j) => tr.insertCell().textContent = j ? person[col] ?? '-' : i);
}, table.createTBody());
document.body.append(table);
$addres.val("Мои данные").change();
.change()
на [0].dispatchEvent(new Event('input'))
. const find = (data, key) => Object
.entries(data instanceof Object ? data : {})
.reduce((found, [ k, v ]) => found ?? (k === key ? v : find(v, key)), null);
function find(data, key) {
for (const stack = [ data ]; stack.length;) {
const n = stack.pop();
if (n?.hasOwnProperty(key)) {
return n[key];
}
stack.push(...Object.values(n ?? {}));
}
return null;
}
const $section = $('.section').on('click', () => $section.addClass('opened'));
$section.find('.close').on('click', e => {
e.stopPropagation();
$section.removeClass('opened');
});
// или
const section = document.querySelector('.section');
section.addEventListener('click', () => section.classList.add('opened'));
section.querySelector('.close').addEventListener('click', e => (
e.stopPropagation(),
section.classList.remove('opened')
));
const $section = $('section').click(e => {
$section.toggleClass('opened', !$(e.target).is('.close'));
});
// или
document.querySelector('.section').addEventListener('click', e => {
e.currentTarget.classList.toggle('opened', !e.target.matches('.close'));
});