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.removeNamedItem(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(({ id, name, value }) => {
((group.values[id] ||= { id, name })[key] ||= []).push(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
))
}));
const xxx = ([...str]) => [...new Set(Array.from(
{ length: str.length * 10 },
(n, i) => str.map((m, j) => (j === (i / 10 | 0)) ? i % 10 : m).join('')
))];
function xxx(str) {
const arr = str.split('');
const result = [ str ];
for (const [ i, n ] of arr.entries()) {
for (let j = 0; j < 10; j++) {
if (j !== +n) {
arr[i] = j;
result.push(arr.join(''));
}
}
arr[i] = n;
}
return result;
}
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 hideOptions = {
1: [ '12', '14', '15' ],
2: [ '1', '11', '16' ],
};
first.addEventListener('change', function() {
Array.prototype.forEach.call(second, function(n) {
n.hidden = this.includes(n.value);
}, hideOptions[this.value] ?? []);
});
.hidden {
display: none;
}
first.onchange = e => {
const toHide = hideOptions[e.target.value];
for (const n of second) {
n.classList.toggle('hidden', toHide?.indexOf(n.value) > -1);
}
};
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);
}
});