Array.prototype.reduce.call(
document.querySelector('table').rows,
(acc, n) => {
if (!n.classList.contains('no')) {
acc[acc.length - 1].info.push({
subtitle: n.querySelector('th').textContent,
cell: n.querySelector('td').textContent,
});
} else if (!n.querySelector('.no2')) {
acc.push({
title: n.querySelector('.car').textContent,
info: [],
});
}
return acc;
},
[]
)
<div ref="map">
mounted() {
this.map = L.map(this.$refs.map).setView([ 55.75222, 37.61556 ], 13);
...
x.domain([
d3.min(data, d => new Date(d.date)).setMonth(-1),
d3.max(data, d => new Date(d.date)),
]);
<v-data-table @click:row="onClickRow">
methods: {
onClickRow(item) {
console.log(item);
},
...
$(this).parents('.portfolio')
function parents(el, selector) {
const p = [];
while ((el = el.parentNode) !== document && el) {
(!selector || el.matches(selector)) && p.push(el);
}
return p;
}
parents(this, '.portfolio')
$(this).parent('.portfolio')
this.parentNode.classList.contains('portfolio') ? this.parentNode : null
$(this).children('.portfolio')
[...this.children].filter(n => n.classList.contains('portfolio'))
// или
Array.prototype.filter.call(this.children, n => n.matches('.portfolio'))
// или
this.querySelectorAll(':scope > .portfolio')
$(this).find('.portfolio')
this.querySelectorAll('.portfolio')
$(this).next('.portfolio')
(el => el && el.matches('.portfolio') ? el : null)(this.nextElementSibling)
const dropzone = event.currentTarget;
dropzone.insertBefore(draggableElement, event.target.closest('tr').nextElementSibling);
event.target.closest('tr').after(draggableElement);
new Vue({
store: store,
...
new Vue({
store: createStore(),
...
попытался решить все через рекурсию
const createTree = (data, idKey, parentKey, parentId) =>
data.reduce((acc, n) => (parentId === n[parentKey] && acc.push({
...n,
children: createTree(data, idKey, parentKey, n[idKey]),
}), acc), []);
const tree = createTree(data, 'id', 'parentId', null);
function createTree(data, idKey, parentKey) {
const tree = Object.fromEntries(data.map(n => [ n[idKey], { ...n, children: [] } ]));
return Object
.values(tree)
.filter(n => !(tree[n[parentKey]] && tree[n[parentKey]].children.push(n)));
}
const tree = createTree(data, 'id', 'parentId');
передавать параметры <...> оставив в computed
methods: {
filterHeroes(attr) {
const s = this.searchHeroesString.toLowerCase();
return this.heroes.filter(n => n.hero_attribute === attr && n.name.toLowerCase().includes(s));
},
data: () => ({
active: false,
}),
created() {
const onClick = e => this.active = this.$refs.block.contains(e.target) && this.active;
document.addEventListener('click', onClick);
this.$on('hook:beforeDestroy', () => document.removeEventListener('click', onClick));
},
<button @click.stop="active = !active">click me</button>
<div :class="{ active }" ref="block">hello, world!!</div>
state: {
opened: null,
...
<Trigger :block="block">
props: [ 'block' ],
computed: mapState([ 'opened' ]),
:class="{ 'active' : block === opened }"
@click="toggleNav(block)"
toggleNav(state, block) {
state.opened = state.opened === block ? null : block;
},
state.opened = block
(название мутации в этом случае конечно следует поменять).closeSidebarPanel(state) {
state.opened = null;
},
isPanelOpen(state) {
return !!state.opened;
},
<span v-if="isPanelOpen">{{ $store.state.opened.bName }}</span>
<slot :block="$store.state.opened"></slot>
<template #default="{ block }">
<div class="sidebar-panel-settings">
<div class="setting-block">
{{ block.bName }}
</div>
</div>
</template>