const select = document.querySelector('вам виднее, что тут должно быть');
const values = [ '1', '2', '3' ];[...select].forEach(n => values.includes(n.value) && n.remove());for (const n of select.querySelectorAll(values.map(n => `[value="${n}"]`))) {
select.removeChild(n);
}select.replaceChildren(...Array.prototype.filter.call(
select,
((values, n) => !values.has(n.value)).bind(null, new Set(values))
));Array.prototype.reduceRight.call(
select.options,
(_, n) => ~values.indexOf(n.value) && n.replaceWith(),
null
);select.innerHTML = Array
.from(select.children)
.filter(function(n) {
return n.matches(this);
}, `:not(${values.map(n => `[value="${n}"]`)})`)
.map(n => n.outerHTML)
.join('');(function next(i, n = select.item(--i)) {
if (n) {
for (const v of values) {
if (v === n.value) {
n.outerHTML = '';
break;
}
}
next(i);
}
})(select.length);
Обычный img у меня не сработал.
product.amount = 1; на Vue.set(product, 'amount', 1);.product.amount = 1;
state.items.push(product);state.items.push({
...product,
amount: 1,
});
const filterArrByObj = (arr, obj) =>
Object.entries(obj).reduce((arr, [ k, v ]) => {
return arr.filter(Array.isArray(v)
? n => v.includes(n[k])
// !v.length || v.includes(n[k]), если при пустом массиве допустимо любое значение
: n => v === n[k]
// n[k].includes(v), если точное соответствие не нужно
);
}, arr);computed: {
filteredData() {
return filterArrByObj(this.data, this.filters);
},
},<tr v-for="n in filteredData">
...
calc__price и calc__payment заменить на общий calc.const $price = $('#price');
const $firstPayment = $('#first-payment');
function update($elem) {
$elem.closest('.calc').find('output').text($elem.val());
$('.payment-percent').html(Math.round($firstPayment.val() * 100 / $price.val()) + '%');
}
$price.closest('.calc').on('input', function() {
const val = $price.val();
$firstPayment
.val((i, v) => Math.min(v, val))
.attr('max', val)
.rangeslider('update', true);
update($firstPayment);
});
$price.add($firstPayment)
.rangeslider({ polyfill: false })
.closest('.calc')
.on('input', e => update($(e.target)))
.end()
.trigger('input');
function walkNested(val, callback) {
callback(val);
if (val instanceof Object) {
Object.values(val).forEach(n => walkNested(n, callback));
}
}function walkNested(val, callback) {
for (const stack = [ val ]; stack.length;) {
const n = stack.pop();
callback(n);
if (n instanceof Object) {
stack.push(...Object.values(n));
}
}
}walkNested(obj, n => n?.touched === true && (n.touched = false));
const keys = [ 'city', 'country' ];.const newArr = arr.map(n => Object.fromEntries(Object.values(n).map((v, i) => [ keys[i], v ])));arr.forEach(n => Object.entries(n).forEach(([ k, v ], i) => (delete n[k], n[keys[i]] = v)));
str.replace(/\t.*/s, '')
// или
str.match(/^[^\t]*/)[0]
// или
str.slice(0, str.search(/\t|$/))
// или
str.split('\t', 1).pop()
// или
[...str].reduceRight((acc, n) => n === '\t' ? '' : n + acc, '')
const sourceSelector = '#menu a';
const targetSelector = '#submenu > ul';$source = $(sourceSelector);
$(targetSelector).width(i => $source.eq(i).width());
// или
document.querySelectorAll(targetSelector).forEach(function(n, i) {
n.style.width = `${this[i].offsetWidth}px`;
}, document.querySelectorAll(sourceSelector));
const min = 7;
const max = min + 21;
function update(value) {
value = Math.max(min, Math.min(max, value | 0));
$('#spinner2').val(value);
$('#slider2').slider('value', value);
const date = new Date();
date.setDate(date.getDate() + value);
$('#amount').val(date.toLocaleString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
}));
}
$('#slider2').slider({
range: 'min',
min,
max,
step: 1,
slide: (e, ui) => update(ui.value),
});
$('#spinner2').spinner({
min,
max,
spin: (e, ui) => update(ui.value),
}).on('input', e => update(e.target.value)).trigger('input');
Мои текущие знания и умения:
const sort = {
number: (a, b) => a - b,
string: (a, b) => a.localeCompare(b),
};function sortTable(table, colIndex) {
if (typeof table === 'string') {
table = document.querySelector(table);
}
const head = table.tHead.rows[0];
const compare = sort[head.cells[colIndex].dataset.type] ?? sort.string;
const value = row => row.cells[colIndex].innerText;
const tbody = table.tBodies[0];
tbody.append(...[...tbody.rows].sort((a, b) => compare(value(a), value(b))));
[...head.cells].forEach((n, i) => n.classList.toggle('sorted', i == colIndex));
}.sorted {
background: #ccc;
}
.sorted::after {
content: " \2193";
}// просто дёргаем сортировку
sortTable('#grid', 0);
sortTable(document.querySelector('table'), 1);
// или, сортируем по клику на заголовки столбцов
document.querySelectorAll('#grid th').forEach(function(n) {
n.addEventListener('click', this);
}, ({ target: t }) => sortTable(t.closest('table'), t.cellIndex));
А можно как-то присваивать свой класс?
computed: {
activeLink() {
return this.links.find(n => n.url === this.$route.path);
},
},:class="{ active: activeLink === link }"