const containerSelector = '.card';
const selectSelector = `${containerSelector} select`;
const dataAttr = 'name';
$(selectSelector).change(function() {
$(this)
.closest(containerSelector)
.find(`[data-${dataAttr}]`)
.hide()
.filter(`[data-${dataAttr}="${this.value}"]`)
.show();
}).val(defaultValueSelected).trigger('change');
// или
const selects = document.querySelectorAll(selectSelector);
const onChange = ({ target: t }) => t
.closest(containerSelector)
.querySelectorAll(`[data-${dataAttr}]`)
.forEach(n => n.style.display = t.value === n.dataset[dataAttr] ? 'block' : 'none');
selects.forEach(n => {
n.value = defaultValueSelected;
n.addEventListener('change', onChange);
n.dispatchEvent(new Event('change'));
});
const tree = ref(null)
return {
tree,
...
<el-tree
ref="tree"
...
tree.value.getCheckedKeys()
. export default ({ filter, checked, onChange, children }) => (
<div>
<label>
<input
type="checkbox"
name={filter}
onChange={() => onChange(filter)}
checked={checked}
/>
{children}
</label>
</div>
);
function getURLs($arr, $path = []) {
$urls = [];
foreach ($arr as $item) {
array_push($path, $item['slug']);
array_push($urls, '/'.implode('/', $path).'/', ...getURLs($item['children'], $path));
array_pop($path);
}
return $urls;
}
const result = Object.values(arr.reduce((acc, n) => {
(acc[n.name] ??= ({ ...n, count: 0 })).count++;
return acc;
}, {}));
function uniqueWithCount(data, key, countKey) {
const getKey = key instanceof Function ? key : n => n[key];
const unique = new Map;
for (const n of data) {
const k = getKey(n);
unique.set(k, unique.get(k) ?? { ...n, [countKey]: 0 }).get(k)[countKey]++;
}
return unique;
}
const result = [...uniqueWithCount(arr, 'name', 'count').values()];
это вообще реально?
foreach ($arr as $item) {
$id = $item['id_product_attribute'];
if (!isset($result[$id])) {
$result[$id] = $item;
} else {
$result[$id]['attribute_name'] .= ', '.$item['attribute_name'];
}
}
const table = document.querySelector('тут селектор вашей таблицы');
table.querySelectorAll('tbody td:last-child').forEach(
(n, i, { [~-i]: { innerText: prev } = {} }) =>
n.innerText !== prev && (n.innerHTML = `<a href="#">${n.innerText}</a>`)
);
// или
let prev = null;
for (const { rows } of table.tBodies) {
for (const { lastElementChild: n } of rows) {
const curr = n.textContent;
if (curr !== prev) {
n.innerHTML = '<a href="#">' + (prev = curr) + '</a>';
}
}
}
return { ...user, isFollowed: !this.isFollowed };
const chunks = (arr, chunkSize) => Array.from(
{ length: Math.ceil(items.length / chunkSize) },
(n, i) => items.slice(i * chunkSize, (i + 1) * chunkSize)
);
const Card = props => (
<div className="style-review__slide-row">
<a className="style-card style-review__style-card" href="#">
<div className="style-card__overlay">
<div className="style-card__title">{props.title}</div>
<div className="style-card__category">
{props.category}
</div>
</div>
</a>
</div>
);
const chunkedItems = chunks(items, 3);
<Swiper>
{chunkedItems.map(cardItems => (
<SwiperSlide className="swiper-slide style-review__slide">
{cardItems.map(n => <Card {...n} />)}
</SwiperSlide>
))}
</Swiper>
// создаём новый массив
const newArr = arr.map(({ name, ...n }) => (n.user_name = name, n));
// изменяем существующий:
arr.forEach(n => (n.user_name = n.name, delete n.name));
// keys - объект вида { старый_ключ_1: 'новый_ключ_1', старый_ключ_2: 'новый_ключ_2', ... }
const renameKeys = (obj, keys) =>
Object.fromEntries(Object
.entries(obj)
.map(([ k, v ]) => [ keys.hasOwnProperty(k) ? keys[k] : k, v ])
);
const newArr = arr.map(n => renameKeys(n, { name: 'user_name' }));
function renameKeys(obj, keys) {
for (const n of Object.entries(keys)) {
if (obj.hasOwnProperty(n[0])) {
obj[n[1]] = obj[n[0]];
delete obj[n[0]];
}
}
}
arr.forEach(n => renameKeys(n, { name: 'user_name' }));
state = {
markers: [],
maxMarkersNum: 666,
}
onClick = ({ latlng }) => {
this.setState(({ markers, maxMarkersNum }) => ({
markers: markers.length >= maxMarkersNum
? []
: [ ...markers, latlng ],
}));
}
<Map onClick={this.onClick}>
{this.state.markers.map(n => <Marker position={n} />)}
</Map>
В App.vue я запрашиваю все продукты из БД
store.dispatch('GET_PRODUCTS').then(() => {
new Vue({ ... });
});
watch: {
'$store.state.products': {
immediate: true,
handler(products) {
if (products) {
// можно что-то сделать
}
},
},
},
$arr = array_slice(explode(' ', $str), 1);
.array_map(fn($n) => trim($n, '"'), $arr)
. const isSumEven = arr => arr.reduce((p, c) => p ^ c, 1) & 1;
// или
const isSumEven = arr => !(arr.filter(n => n % 2).length % 2);
// или
const isSumEven = arr => Number.isInteger(arr.reduce((acc, n) => acc + n, 0) / 2);
// или
const isSumEven = arr => /[02468]$/.test(eval(arr.join('+')) ?? 0);
const result = arr.filter(isSumEven);
.