Количество LI элементов заранее не известно, поэтому выполнять функцию WHEN с определенным количеством аргументов нет возможности.
$.when(...$('li').get().map(n => $.ajax())).then(/* выполняйте, чо там вам надо */);
this.data = new Proxy(...
сделайтеreturn new Proxy(this, {
get(target, name) {
return name in target
? target[name]
: `Свойства ${name} нет`
},
});
created() {
const onClickOutside = e => this.opened = this.$el.contains(e.target) && this.opened;
document.addEventListener('click', onClickOutside);
this.$on('hook:beforeDestroy', () => document.removeEventListener('click', onClickOutside));
},
for (const [ k, v ] of new URLSearchParams(url.replace(/.*\?/, ''))) {
document.querySelector(`#${k}`).value = v;
}
url
.slice(url.indexOf('?') + 1)
.split('&')
.map(n => n.split('='))
.forEach(n => document.getElementById(n[0]).value = n[1]);
const data = [...url.split('?').pop().matchAll(/([^&]+)=([^&]*)/g)];
for (let i = 0; i < data.length; i++) {
document.querySelector(`[id="${data[i][1]}"]`).value = data[i][2];
}
const getMonthName = iMonth =>
new Date(0, iMonth).toLocaleString('ru-RU', { month: 'long' });
computed: {
groupedByMonth() {
return this.items.reduce((acc, n) => {
const key = getMonthName(n.date.split('-')[1] - 1);
(acc[key] = acc[key] || []).push(n);
return acc;
}, {});
},
},
<ul>
<li v-for="(items, month) in groupedByMonth" :key="month">
<h3>{{ month }}</h3>
<ul>
<li v-for="n in items" :key="n.id">{{ n }}</li>
</ul>
</li>
</ul>
groupedByMonth() {
return this.items.reduce((acc, n) => {
acc[n.date.split('-')[1] - 1].items.push(n);
return acc;
}, Array.from({ length: 12 }, (_, i) => ({
month: getMonthName(i),
items: [],
})));
},
<ul>
<li v-for="{ items, month } in groupedByMonth" :key="month">
<h3>{{ month }}</h3>
<ul v-if="items.length">
<li v-for="n in items" :key="n.id">{{ n }}</li>
</ul>
<div v-else>данных нет</div>
</li>
</ul>
import router from './router.js';
const url = `/api/photos?${в зависимости от router.currentRoute}=true&page=${list}&limit=15`;
<gmap-map
ref="map"
v-bind="options"
@click="onMapClick"
>
<gmap-marker
v-for="m in markers"
:key="m.id"
:position="m.position"
:clickable="true"
:draggable="true"
@click="onMarkerClick"
/>
</gmap-map>
data: () => ({
options: {
center: { lat: 45.101637, lng: 38.986345 },
zoom: 15,
},
markers: [],
}),
methods: {
onMapClick(e) {
this.markers.push({
id: 1 + Math.max(0, ...this.markers.map(n => n.id)),
position: e.latLng,
});
},
onMarkerClick(e) {
this.$refs.map.panTo(e.latLng);
// или
// this.options.center = e.latLng;
},
},
.hover {
opacity: 0.5;
}
const map = document.querySelector('.map svg');
map.addEventListener('mouseover', onHover);
map.addEventListener('mouseout', onHover);
function onHover({ target: t }) {
this.querySelectorAll('.hover-effect').forEach(n => {
n.classList.toggle('hover', n !== t && this !== t);
});
}
Если выводить в консоль то коллекции не чем не отличаются.
HTMLCollection
, хранящая элементы DOM, является динамической. При изменении документа она моментально отражает все произведённые изменения.
foreach ($array as [ 'id' => $id, 'taste' => $taste ]) {
$result[$id][$taste] = 1 + ($result[$id][$taste] ?? 0);
}
$('.scheme-wrap polygon').click(function() {
$(`.scheme-wrap__item[data-id="${this.dataset.id}"] .scheme-wrap__popup`).show();
});
.scheme-wrap__popup.visible {
display: block;
}
document.querySelectorAll('.scheme-wrap polygon').forEach(n => {
n.addEventListener('click', onClick);
});
function onClick({ currentTarget: { dataset: { id } } }) {
const selector = `.scheme-wrap__item[data-id="${id}"] .scheme-wrap__popup`;
const popup = document.querySelector(selector);
if (popup) {
popup.classList.add('visible');
}
}
const groupedUsers = users && users.reduce((acc, n) => {
acc[new Date(n.dob).getMonth()].users.push(n);
return acc;
}, [...Array(12)].map((n, i) => ({
month: new Date(0, i).toLocaleString('ru-RU', { month: 'long' }),
users: [],
})));
{groupedUsers && groupedUsers.map(n => (
<div key={n.month}>
<h2>{n.month}</h2>
{n.users.map(user => (
<div key={user.id}>
<h3>user #{user.id}</h3>
<div>данные пользователя...</div>
</div>
))}
</div>
))}
document.addEventListener('click', function(e) {
if (e.target.classList.contains('sbros')) {
for (let el = e.target; el = el.previousElementSibling;) {
if (el.classList.contains('fields')) {
el.value = el.getAttribute('default-value');
break;
}
}
}
});
document.addEventListener('click', ({ target: t }) => {
if (t.matches('.sbros')) {
const el = t.closest('здесь селектор обёртки').querySelector('.fields');
el.value = el.getAttribute('default-value');
}
});
const inputs = document.querySelectorAll('.fields');
const buttons = [...document.querySelectorAll('.sbros')];
buttons.forEach(n => n.addEventListener('click', onClick));
function onClick(e) {
const el = inputs[buttons.indexOf(e.target)];
el.value = el.getAttribute('default-value');
}