methods: {
trClass: rowData => rowData.is_blocked && 'table-danger',
...
<b-table
:tbody-tr-class="trClass"
...
const Filter = ({ title, values, value, onChange }) => (
<div>
<h3>{title}</h3>
{values.map(n => (
<label>
<input
type="radio"
onChange={() => onChange(n)}
checked={value === n}
/>
{n}
</label>
))}
</div>
);
state = {
...
filteredProducts: [],
status: 'all',
}
onFilterStatusChange = status => {
this.setState({ status });
}
filterProducts() {
this.setState(({ status }) => ({
filteredProducts: status === 'all'
? this.state.products
: this.state.products.filter(n => n.prod_status.includes(status)),
}));
}
componentDidUpdate(prevProps, prevState) {
if (this.state.status !== prevState.status) {
this.filterProducts();
}
}
render() {
...
<Filter
title="Status:"
values={[ 'all', 'recommended', 'saleout', 'bestseller', 'new' ]}
value={this.state.status}
onChange={this.onFilterStatusChange}
/>
<Products products={this.state.filteredProducts} />
...
}
<div className="status">{status}</div>
пусть будет{status.split(',').map(n => <div className="status">{n}</div>)}
function getDividers(num, divider) {
return num === 1
? []
: num % divider
? getDividers(num, divider + 1)
: [ divider, ...getDividers(num / divider, divider) ];
}
function showDividers(num) {
if (!Number.isInteger(num) || num < 2) {
throw 'fuck off';
}
console.log(`${num} = ${getDividers(num, 2).join(' * ')}`);
}
function createTree({
data,
key = 'id',
parentKey = 'parentId',
childrenKey = 'children',
}) {
const tree = Object.fromEntries(data.map(n => [
n[key],
{ ...n, [childrenKey]: [] }
]));
return Object.values(tree).filter(n => (
!tree[n[parentKey]]?.[childrenKey].push(n)
));
}
const result = createTree({
data: components,
childrenKey: 'components',
});
data: () => ({
numArticlesToShow: 5,
...
}),
computed: {
articlesToShow() {
return this.articles.slice(0, this.numArticlesToShow);
},
...
},
<li v-for="n in articlesToShow">
...
</li>
...
<button @click="numArticlesToShow += 5" :disabled="numArticlesToShow >= articles.length">
показать ещё
</button>
const values = Object.values(obj);
const result = values.flat().length;
// или
const result = [].concat(...values).length;
// или
const result = values.reduce((acc, n) => acc + n.length, 0);
// или
const result = eval(values.map(n => n.length).join('+')) ?? 0;
let result = 0;
for (const k in obj) {
result += Object.hasOwn(obj, k) && obj[k].length;
}
this.$set(this.chartOptions.series[0].data, индекс, значение);
что делаю не так?
active
на кнопке? Его у элемента с классом d-n
переключать надо - вместо той ерунды с изменением стилей напрямую. Кстати, а кому вы пытаетесь назначить style.display = 'table-cell'
? Если идти от кнопки parent-parent-next (вместо того, чтобы несколько раз дёргать parentNode, следует использовать метод closest) - это будет (не будет, погуглите, в чём разница между nextSibling
и nextElementSibling
) строка, а не ячейка - так что перенесите-ка класс d-n
на один уровень выше. Зачем создавать каждой кнопке индивидуальный обработчик? Достаточно одного на всех, создавайте его вне цикла. Наконец, у classList.toggle
есть второй параметр, не надо им пренебрегать.document.querySelectorAll('.panel').forEach(n => n.addEventListener('click', onClick));
function onClick() {
const panel = this.closest('tr').nextElementSibling;
const isActive = !panel.classList.contains('active');
panel.classList.toggle('active', isActive);
this.classList.toggle('changing-icon', isActive);
}
мне нужен не сам ответ
function findOutlier(integers) {
const [ p0, p1, p2 ] = integers.slice(0, 3).map(n => n & 1);
return p0 === p1
? integers.find(n => (n & 1) !== p0)
: integers[+(p0 === p2)];
}
const findOutlier = arr => arr
.reduce((acc, n) => (acc[n & 1].push(n), acc), [ [], [] ])
.find(n => n.length === 1)
.pop();
const findOutlier = arr => arr
.sort((a, b) => (a & 1) - (b & 1))
.at(-((arr[0] & 1) === (arr[1] & 1)));
useEffect(() => { document.querySelector('.App').classList.toggle(theme) }, [theme])
useEffect(() => {
const el = document.querySelector('.App');
el.classList.add(theme);
return () => el.classList.remove(theme);
}, [ theme ]);
useEffect(() => {
const newArray = initialState.filter(n => checked.every(m => n[m]));
setData(newArray.length ? newArray : initialState);
}, [ checked ]);
function getFilterByCount(arr, filterFn, key = n => n) {
const getKey = key instanceof Function ? key : n => n[key];
const count = arr.reduce((acc, n) => {
const k = getKey(n);
return acc.set(k, -~acc.get(k));
}, new Map);
return n => !!filterFn(count.get(getKey(n)));
}
const filterByCount = (...args) =>
args[0].filter(getFilterByCount(...args));
const newArr = filterByCount(arr, count => count > 1, 'props1');
function deleteByCount(arr, filterFn, key) {
const f = getFilterByCount(arr, filterFn, key);
arr.length -= arr.reduce((acc, n, i, a) => (
a[i - acc] = n,
acc + f(n)
), 0);
}
deleteByCount(arr, count => count < 2, n => n.props1);
<button @click="onClick">click me</button>
<apexchart
ref="chart"
...
methods: {
onClick() {
this.$refs.chart.zoomX(...);
},
...