computed: {
stationsWithCars() {
return this.cars.reduce(
(acc, n) => (acc[n.address]?.cars.push(n), acc),
Object.fromEntries(this.stations.map(n => [ n.name, { station: n, cars: [] } ]))
);
},
},
<div v-for="{ station, cars } in stationsWithCars" :key="station.id">
<h1>{{ station.name }}</h1>
<ul>
<li v-for="car in cars" :key="car.id">{{ car.name }}</li>
</ul>
</div>
tableEl
.querySelectorAll('tbody td')
.forEach(td => Array
.from(td.attributes)
.forEach(attr => td.removeAttribute(attr.name))
);
for (const tbody of tableEl.tBodies) {
for (const tr of tbody.rows) {
for (const { attributes: a } of tr.cells) {
for (let i = a.length; i--;) {
a[i].ownerElement.removeAttribute(a[i].name);
}
}
}
}
const toCamelCase = val =>
val instanceof Array
? val.map(toCamelCase)
: val instanceof Object
? Object.fromEntries(Object
.entries(val)
.map(n => [
n[0].replace(/_+(.)/g, (m, g1) => g1.toUpperCase()),
toCamelCase(n[1]),
])
)
: val;
onFrame(e, data) {
if (!data.frame) {
data.reverse = !data.reverse;
}
},
Многие твердят: решай задачи. Ну, ок, допустим, беру какую-нибудь задачу. Прочёл текст. А дальше-то что? Я не знаю как подойти к решению задачи, с чего начать, что вообще делать и чем закончить.
array_slice($data, $offset)
array_slice($data, $offset, $size_page)
.if ($page <= $size_page) {
array_diff($arrays, [ "none"]);
- этот способ Не работает
$newArrays = array_map(fn($arr) => array_diff($arr, [ 'none' ]), $arrays);
v-for="area in `${ this.$route.params.type }Areas`"
v-for="area in this[`${$route.params.type}Areas`]"
разве vue не повсеместно лишает возможности мутировать данные родителя в потомках?
как вообще так вышло, что v-model внизу сумел изменить serviceBlocksBlocks
const average = arr => arr.reduce((acc, n) => acc + n, 0) / arr.length;
const extractValues = (group, item, key) => item[key].forEach(n => ((group.values[n.id] ||= { id: n.id, name: n.name })[key] ||= []).push(n.value));
const result = Object
.values(arr
.flatMap(n => n.properties.groups)
.reduce((acc, n) => (
acc[n.id] ||= {
id: n.id,
name: n.name,
wellBeing: [],
values: {},
},
acc[n.id].wellBeing.push(n['well-being']),
extractValues(acc[n.id], n, 'needs'),
extractValues(acc[n.id], n, 'provision'),
acc
), {}))
.map(n => ({
id: n.id,
name: n.name,
value: average(n.wellBeing),
values: Object.values(n.values).map(m => (
m.needs = average(m.needs),
m.provision = average(m.provision),
m
))
}));
data: () => ({
items: [ 1, 25, 32, 4, 5 ],
filter: false,
}),
computed: {
filteredItems() {
return this.items.filter(n => n < 10);
},
},
<label>
<input type="checkbox" v-model="filter">
Фильтровать
</label>
<ul>
<li v-for="n in (filter ? filteredItems : items)">{{ n }}</li>
</ul>
Я не меняю prop href
@Prop(String) href = '';
It's not supported to define eachdefault
property like@Prop() prop = 'default value'
.
const first = document.querySelector('#first');
const second = document.querySelector('#second');
const showOptions = {
1: [ '1', '11', '16' ],
2: [ '12', '14', '15' ],
};
first.addEventListener('change', function() {
const toShow = showOptions[this.value];
[...second].forEach(n => n.hidden = +n.value && toShow && !toShow.includes(n.value));
});
const nav = document.querySelector('.nav');
const itemSelector = '.nav-link';
const image = document.querySelector('.preview-img');
const category = document.querySelector('.preview-head');
function updatePreview(data) {
image.src = data.img;
category.textContent = data.category;
}
nav.querySelectorAll(itemSelector).forEach(function(n) {
n.addEventListener('mouseenter', this);
}, e => updatePreview(e.target.dataset));
nav.addEventListener('mouseover', e => {
const data = e.target.closest(itemSelector)?.dataset;
if (data) {
updatePreview(data);
}
});