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, $элементыКоторымНадоЗадаватьСлучайныеКоординаты);
const formTemplate = `<здесь html-код формы>`;
$(document).on('change', 'селектор чекбокса', function() {
const $el = $(this).closest('селектор формы');
if (this.checked) {
$el.after(formTemplate);
} else {
$el.nextAll('селектор формы').remove();
}
});
@click="testClickGo().restart"
targets: '.testVal',
data: () => ({
anime: null,
}),
mounted() {
this.anime = this.$anime({
targets: this.$refs.animeEl,
translateX: 200,
delay: 800,
});
},
<h1 ref="animeEl">hello, world!!</h1>
<button @click="anime.restart()">click me</button>
v-model
.const group = (arr, keyProp, childrenProp) =>
Object.values(arr.reduce((acc, { [childrenProp]: children, ...n }) => {
const item = acc[n[keyProp]] = acc[n[keyProp]] || n;
if (children) {
children = (item.childItems || []).concat(children);
item[childrenProp] = group(children, keyProp, childrenProp);
}
return acc;
}, {}));
const grouped = group(products, 'name', 'childItems');
switch (true) {
case one.includes(inp):
...
break;
case two.includes(inp):
...
break;
}
const arr = [
{
values: [ ... ],
action: () => { ... },
},
{
values: [ ... ],
action: () => { ... },
},
];
arr.find(n => n.values.includes(inp))?.action();
preg_match_all('~(?<=<p>).+?(?=</p>)~', $str, $match);
$data = array_map(function($n) {
return explode('-', $n, 2);
}, $match[0]);
str.split('"').filter((n, i) => i & 1)
// или
str.match(/".*?"/g)?.map(n => n.slice(1, -1)) ?? []
// или
Array.from(str.matchAll(/"([^"]*)"/g), n => n[1])
// или
Array.prototype.reduce.call(str, (acc, n) => {
if (n !== '"') {
acc[1]?.push(n);
} else if (acc[1]) {
acc[0].push(acc[1].join(''));
acc[1] = null;
} else {
acc[1] = [];
}
return acc;
}, [ [], null ])[0]
Если происходит перемещение элементов, то счетчик увеличивается на 3, потому что происходит 3 операции с элементами.
[ arr[j - 1], arr[j] ] = [ arr[j], arr[j - 1] ];
swap(arr, j - 1, j); // функция меняет местами элементы, но как именно - вам неизвестно
делаю все как показано в примере в оф. репозитории
API: Container
Component that contains the draggable elements or components. Each of its children should be wrapped by Draggable component
<Container @drop="$emit('drop', row.id)" :get-child-payload="getChildPayload"> <div class="row">
const result = arr1.map((n, i) => {
const index = Math.min(i * 2, ((arr2.length - 2) / 2 | 0) * 2);
return `name: ${n} val1: ${arr2[index]} val2: ${arr2[index + 1]}`;
});
result.forEach(alert);