.map(n => ({ ...n, actv: false }))
.map(n => (n.actv = false, n))
или после монтирования компонента?
mounted() {
this.postsData.forEach(n => this.$set(n, 'actv', false));
},
mounted() {
this.postsData = this.postsData.map(n => ({ ...n, actv: false }));
},
const icons = {
one: [ 'url иконки раскрытия одного элемента', 'и закрытия' ],
all: [ 'url иконки раскрытия всех', 'что здесь должно быть, думаю догадаетесь' ],
};
const getState = el => $(el)
.closest('.team__info-worklog')
.find('.worklog-table')
.get()
.map(n => $(n).is(':visible'));
const setState = (el, state) => $(el)
.closest('.team__info-worklog')
.find('.worklog-table').each((i, n) => $(n)[state[i] ? 'slideDown' : 'slideUp']()).end()
.find('.worklog-expend-all img').attr('src', icons.all[+state.some(Boolean)]).end()
.find('.worklog-list__expend img').attr('src', i => icons.one[+state[i]]);
const createUpdater = f => e => setState(e.target, f(getState(e.target), e));
$('.worklog-expend-all').on('click', createUpdater(state => {
return Array(state.length).fill(!state.some(Boolean));
}));
$('.team__info-worklog').on('click', '.worklog-list__expend', createUpdater((state, e) => {
const index = $(e.target).closest('.worklog-list__row').index();
return state.map((n, i) => i === index ? !n : n);
}));
const blockSelector = '.block';
const buttonSelector = `${blockSelector} button`;
const itemSelector = `${blockSelector} span`;
document.addEventListener('click', e => e
.target
.closest(buttonSelector)
?.closest(blockSelector)
?.append(document.querySelector(itemSelector))
);
const item = document.querySelector(itemSelector);
const onClick = e => e.currentTarget.closest(blockSelector).appendChild(item);
document.querySelectorAll(buttonSelector).forEach(n => n.addEventListener('click', onClick));
$keys = array_keys($arr);
$newArr = array_combine($keys, array_map(null, $arr, array_slice($keys, 1)));
const initialValues = [ 100, 100000 ];
const setValues = values => $inputs.val(i => values[i]);
const $slider = $('#slider-range').slider({
range: true,
min: initialValues[0],
max: initialValues[1],
step: 20,
values: initialValues,
slide: (e, ui) => setValues(ui.values),
});
const $inputs = $('#amount_before, #amount_after')
.on('input', () => $slider.slider('values', $inputs.get().map(n => n.value)));
setValues(initialValues);
onChange={this.props.filterItems}
filterItems = ({ target: { name, checked } }) => {
this.setState({
[name]: checked,
});
}
const select = document.querySelector('[name="id_car_mark"]');
blackList
:const options = Object.fromEntries(Array.from(select, n => [ n.innerText, n ]));
select.prepend(...blackList.reduce((acc, n) => ((n = options[n]) && acc.push(n), acc), []));
select.append(...Array.prototype.filter.call(select, function(n) {
return !this.has(n.textContent);
}, new Set(blackList)));
$('form').on('input', function() {
const disabled = $('[type="text"]', this).get().some(n => n.value.length < 5);
$('[type="submit"]', this).prop({ disabled });
});
document.querySelector('form').addEventListener('input', e => {
e.currentTarget.querySelector('[type="submit"]').disabled = Array
.from(e.currentTarget.querySelectorAll('[type="text"]'))
.some(n => n.value.length < 5);
});
.main-header__menu
. Увели курсор на другой элемент - меню пропало..main-header__menu:hover + .main-header__wrap-submenu,
.main-header__wrap-submenu:hover {
opacity: 1;
visibility: visible;
}
<h1 class="header">click me</h1>
<h1 class="header">click me</h1>
<h1 class="header">click me</h1>
const text = [ 'hello, world!!', 'fuck the world', 'fuck everything' ];
$('.header').click(function() {
const index = $(this).data('index') || 0;
$(this).text(text[index]).data('index', (index + 1) % text.length);
});
<Route path="/:id" component={SinglePhoto} /> <Route path="/history" component={SearchHistory} />
computed: {
tasksGroupedByCategory() {
return this.tasks.reduce(
(acc, n) => (acc[n.category].push(n), acc),
Object.fromEntries(this.boards.map(n => [ n.name, [] ]))
);
},
},
<div v-for="b in boards">
<h2>{{ b.title }}</h2>
<div v-for="n in tasksGroupedByCategory[b.name]">
{{ n.title }}
</div>
</div>
const findPath = (obj, val) =>
Object.is(obj, val)
? []
: Object.entries(obj instanceof Object ? obj : {}).reduce((found, n) => {
if (!found) {
found = findPath(n[1], val);
if (found) {
found.unshift(n[0]);
}
}
return found;
}, null);
function findPath(obj, val) {
for (const stack = [ [ obj, [] ] ]; stack.length;) {
const [ n, keys ] = stack.pop();
if (Object.is(n, val)) {
return keys;
}
if (n instanceof Object) {
stack.push(...Object.entries(n).reverse().map(([ k, v ]) => [ v, [ ...keys, k ] ]));
}
}
return null;
}
setInterval($items => {
$items.each(i => $items.eq(i).css({
left: `${Math.random() * window.innerWidth}px`,
top: `${Math.random() * window.innerHeight}px`,
}));
}, 500, $элементыКоторымНадоЗадаватьСлучайныеКоординаты);