const itemSelector = '.header';
const buttonSelector = `${itemSelector} .delete_block`;
const remove = el => el.closest(itemSelector).remove();
document.querySelectorAll(buttonSelector).forEach(function(n) {
n.addEventListener('click', this);
}, e => remove(e.target));
document.addEventListener('click', ({ target: t }) => (
t.matches(buttonSelector) && remove(t)
));
import re
def has_consecutive_characters(s, count):
return bool(re.search(rf'([\dA-Z])\1{{{count - 1}}}', s, re.IGNORECASE))
arr = [
'PAaAssword',
'Paaaassword',
'P111ssword',
'Password',
]
print([ has_consecutive_characters(n, 3) for n in arr ])
const getTruthyKeys = obj =>
Object
.entries(obj)
.filter(n => n[1])
.map(n => n[0]);
for([key, value] of Object.entries(item)) {
const obj = new Proxy({
a: 0,
b: 1,
c: 2,
}, {
get: () => Math.round(Math.random()),
});
console.log(Array.from({ length: 10 }, () => getTruthyKeys(obj)));
<button :disabled="!данные" @click="onClick">
computed: {
model() {
return new Proxy(Object.fromEntries(this.obj2.map(n => [ n.model, null ])), {
get: (target, prop) => typeof prop === 'string'
? prop.split('.').reduce((p, c) => p?.[c], this.obj)
: target[prop],
set: (target, prop, value) => {
const keys = prop.split('.');
const key = keys.pop();
const obj = keys.reduce((p, c) => (!p.hasOwnProperty(c) && this.$set(p, c, {}), p[c]), this.obj);
this.$set(obj, key, value);
return true;
},
});
},
},
<div v-for="(v, k) in model">
<input v-model="model[k]">
</div>
computed: {
model() {
return this.obj2.map(n => {
const keys = n.model.split('.');
const key = keys.pop();
const obj = keys.reduce((p, c) => p?.[c], this.obj);
return obj && { obj, key };
}).filter(Boolean);
},
},
<div v-for="n in model">
<input v-model="n.obj[n.key]">
</div>
li:not(:first-child, :last-child)
li:not(:first-child):not(:last-child)
li {
/* тут стили для всех элементов */
}
li:first-child,
li:last-child {
/* здесь сбрасываете стили, установленные выше */
}
const replaceValues = (val, test, replacer) =>
val instanceof Array
? val.map(n => replaceValues(n, test, replacer))
: val instanceof Object
? Object.fromEntries(Object
.entries(val)
.map(([ k, v ]) => [
k,
test(k, v)
? replacer(v)
: replaceValues(v, test, replacer)
])
)
: val;
const newData = replaceValues(
data,
k => k.includes('Date'),
v => v.replace(/(\d+)-(\d+)-/, '$2.$1.')
);
получить массив
Object.values
. присвоить первому массиву значения второго только без первого элемента
$('.content_toggle').click(function() {
const $button = $(this);
$(`#box-${this.id.split('-').pop()}`).slideToggle(300, function() {
const isHidden = $(this).is(':hidden');
$button
.text(isHidden ? 'Показать текст' : 'Скрыть текст')
.toggleClass('open', !isHidden);
});
return false;
});
$(this).closest('здесь селектор общего предка').find('.content_block')
$(this).next()
$('.content_block').eq($('.content_toggle').index(this))
echo preg_replace_callback('~\[(.+?)\]~', fn($m) => $array[$m[1]] ?? $m[0], $message);
По клику на кнопку вызывается мутация, в которою передаётся id.
Я так понимаю, потому что метод возвращает только false/true, а не измененный item.
id передается, проверял через консоль
...mapMutations(['chekedItem', 'deleteItem']), itemSucces(id) { this.chekedItem({id}); },
chekedItem: (state, item) => item.checked = !item.checked,
$(document).on('click', 'a[id^="answer_"]', e => $(`#comment_${e.target.id}`).toggle());