filters: {
shorten: (val, words = 2) => val.split(' ').slice(0, words).join(' '),
},
<div>{{ text | shorten }}</div>
<div>{{ text | shorten(5) }}</div>
watch: {
'$route.query.page'() {
this.loadCustomers();
},
},
watch: {
'$route.query.page': {
immediate: true,
handler: 'loadCustomers',
},
},
нужного функционала нет <...> Сталкивался может кто с подобным и нарыл хорошую обертку для API?
сделатьКрасиво
, и вам самому не надо работать ни головой, ни руками? Нет, такого нет и не будет.if (coord.every((n, i) => n === coordinates[i])) {
placemark.balloon.open();
}
const placemarks = elem.find('.map-balloonContent').get().map(n => createPlacemark({
coord: $(n).data('coord'),
content: $(n).html(),
}));
placemarks.forEach(n => myMap.geoObjects.add(n));
placemarks[0].balloon.open();
elem.on('clickAddress', function(e, coord) {
placemarks.find(n => n.geometry.getCoordinates().every((m, i) => m === coord[i])).balloon.open();
});
function getWinCount(team) {
const el = Array
.from(document.querySelectorAll('.table-item__name'))
.find(n => n.textContent === team);
return el ? +el.closest('tr').children[3].textContent : null;
}
const wins = getWinCount('Уфа');
Мой браузер не поддерживает ES-2015
function getWinCount(team) {
var el = null;
[].concat.apply([], document.querySelectorAll('.table-item__name')).forEach(function(n) {
if (!el && n.textContent === team) {
el = n;
}
});
if (!el) {
return null;
}
do {
el = el.parentNode;
} while (el.tagName !== 'TR');
return +el.children[3].textContent;
}
$('.container').find('h2, h3').each(function(i) {
text = $('.select-list li a').eq(i).text();
не надо код, подскажите алгоритм
function shorten(val) {
if (val <= 10000) {
return val.toString();
}
const thousands = val / 1000;
const rounded = Math.round(thousands);
const deviation = Math.sign(thousands - rounded);
return `${[ '≈', '', '>' ][deviation + 1]}${rounded} т.`;
}
Цена завернута в див price prc-new
$('[name="variant"] option:checked').data('price')
$('.price.prc-new span').text()
$('input').on('input', function() {
$(this).val((i, v) => Math.max(this.min, Math.min(this.max, v)));
});
document.querySelector('input').addEventListener('input', ({ target: t }) => {
t.value = Math.max(t.min, Math.min(t.max, t.value));
});
$('.price').text((i, text) => {
const [ price, currency ] = text.split(' ');
return `${(+price).toLocaleString()} ${currency}`;
});
// или
document.querySelectorAll('.price').forEach(n => {
n.textContent = n.textContent.replace(/\d(?=(\d{3})+\D)/g, '$& ');
});
goods.each.with_index do |n, i|
puts n + " " + prices[i].to_s
end
print goods.zip(prices).map{|n| n.join(" ")}.join("\n")
function toggleClasses(block) {
const info = block.querySelector('.infoWrapper');
block.classList.toggle('marginBottom10');
block.classList.toggle('marginBottom120');
info.classList.toggle('displayNone');
info.classList.toggle('displayBlock');
}
document.addEventListener('click', function(e) {
const block = e.target.closest('.blockSvg');
if (block) {
const prevBlock = document.querySelector('.blockSvg.marginBottom120');
if (prevBlock && prevBlock !== block) {
toggleClasses(prevBlock);
}
toggleClasses(block);
}
});
module.exports = {
chainWebpack: config => {
config
.plugin('html')
.tap(args => {
args[0].minify.removeAttributeQuotes = false;
return args;
})
}
};
<div>{{ address }}</div>
<div ref="map"></div>
data: () => ({
coords: [ ... ],
address: '',
}),
mounted() {
ymaps.ready(() => {
const map = new ymaps.Map(this.$refs.map, { ... });
const marker = new ymaps.Placemark(this.coords, {}, {
draggable: true,
});
marker.events.add('dragend', e => {
this.coords = e.get('target').geometry.getCoordinates();
});
map.geoObjects.add(marker);
this.$watch('coords', {
immediate: true,
handler(coords) {
ymaps.geocode(coords).then(r => {
this.address = r.geoObjects.get(0).properties.get('name');
});
},
});
});
},
const className = 'dop_atr';
const maxlen = 250;
text
функцию - вызывается для каждого элемента набора, принимает текущее текстовое содержимое элемента и возвращает новое:$(`.${className}`).text((i, text) => {
return text[maxlen] ? `${text.substring(0, maxlen)}...` : text;
});
for (const n of document.getElementsByClassName(className)) {
n.innerText = n.innerText.slice(0, maxlen) + (n.innerText.charAt(maxlen) && '...');
}
// или
document.querySelectorAll(`.${className}`).forEach(function(n) {
n.textContent = n.textContent.replace(this, '$1...');
}, RegExp(`(.{${maxlen}}).+`));