const ancestor = 'селектор элементов, которые надо получить';
const descendant = 'селектор вложенных элементов';
Array.prototype.filter.call(
document.querySelectorAll(ancestor),
n => n.querySelector(descendant)
)
Array.from(
document.querySelectorAll(`${ancestor} ${descendant}`),
n => n.closest(ancestor)
)
[...document.querySelectorAll(descendant)].reduce(
(acc, n) => ((n = n.closest(ancestor)) && acc.push(n), acc),
[]
)
document.querySelectorAll(`${ancestor}:has(${descendant})`)
class App extends React.Component {
state = {
classes: [ 'bullshit' ],
}
onFocus = () => {
this.setState(({ classes }) => ({
classes: [ ...classes, 'focus' ],
}));
}
onBlur = () => {
this.setState(({ classes }) => ({
classes: classes.filter(n => n !== 'focus'),
}));
}
render() {
return (
<div className={this.state.classes.join(' ')}>
<input onFocus={this.onFocus} onBlur={this.onBlur} />
</div>
);
}
}
[
[ 'region_id', 'regionName' ],
[ 'district_id', 'districtName' ],
[ 'area_id', 'areaName' ],
[ 'city_id', 'cityName' ],
[ 'place_id', 'cityName' ],
[ 'name', 'streetName' ],
].forEach(([ del, search ]) => {
if (this.tableParam[del]) {
delete this.tableParam[del];
this.searchForm.get(search).patchValue(null);
}
});
state отказывается обновляться
onImportantClick = (e) => {
e.stopPropagation();
this.setState(({ important }) => ({
important: !important
}));
};
const parent = document.querySelector('.box').parentNode;
const iMin = 2;
const iMax = 5;
const wrapper = document.createElement('div');
wrapper.classList.add('wrapper');
if (parent.children[iMin]) {
const elems = Array.prototype.slice.call(parent.children, iMin, iMax);
elems[0].before(wrapper);
wrapper.append(...elems);
}
// или
const elems = parent.querySelectorAll(`:nth-child(n + ${-~iMin}):not(:nth-child(n + ${-~iMax}))`);
if (elems.length) {
parent.insertBefore(wrapper, elems[0]);
elems.forEach(n => wrapper.appendChild(n));
}
// или
if (parent.children.length > iMin) {
parent.children[iMin].insertAdjacentElement('beforebegin', wrapper);
for (let i = iMax - iMin, n = null; i-- && (n = wrapper.nextElementSibling);) {
wrapper.insertAdjacentElement('beforeend', n);
}
}
const result = await Promise.all([ 1, 2, 3 ].map((n, i) => {
return new Promise(resolve => {
setTimeout(() => {
console.log(`timeout #${i}`);
resolve(n * 10);
}, Math.random() * 3000 | 0);
});
}));
console.log('result:', result);
ошибка появилась из ниоткуда
.hidden {
opacity: 0;
}
data: () => ({
items: [
{ text: '...', hidden: true },
{ text: '...', hidden: true },
...
],
}),
mounted() {
this.items.forEach((n, i) => {
setTimeout(() => n.hidden = false, 300 * (i + 1));
});
},
<li v-for="{ text, hidden } in items" :class="{ hidden }">
<a href="">{{ text }}</a>
</li>
const length = 25;
const createItem = i => ({
url: `photos/${i}.jpg`,
// ещё какие-то свойства
});
const items = Array.from({ length }, (_, i) => createItem(i + 1));
// или
const items = [];
for (let i = 1; i <= length; i++) {
items.push(createItem(i));
}
// или
const items = [];
while (items.length < length) {
items[items.length] = createItem(-~items.length);
}
// или
const items = (function createItems(i) {
return i > 0 ? [ ...createItems(i - 1), createItem(i) ] : [];
})(length);
И самое главное, мне нужно потом взять значение этих массивов.
descriptionImage.url - Как-то так
descriptionImage[индекс элемента].url
. не оборачиваются