function isComposite($num) {
// нет, за вас я этого делать не буду, давайте как-нибудь сами...
// в конце концов, можно и нагуглить - это дело трёх секунд
}
$newArr = array_filter($arr, 'isComposite');
const valuesShow = [ 2000, ещё какое-то значение, и ещё, и ещё, ... ];
$('#sample_form_deliv').change(function({ target: { value } }) {
$('#sample_form_pay .input-label:eq(2)').toggle(valuesShow.includes(+value));
});
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>