const selector = '.list-item';
const key1 = 'pagereview';
const key2 = 'pageslug';
const attr1 = `data-${key1}`;
const attr2 = `data-${key2}`;
const $elements = $(selector);
// или
const elements = document.querySelectorAll(selector);
$elements.show().filter((i, n) => $(n).data(key1) !== $(n).data(key2)).hide();
// или
$elements.each(function() {
const $this = $(this);
$this.toggle($this.attr(attr1) === $this.attr(attr2));
});
// или
elements.forEach(n => {
n.hidden = n.getAttribute(attr1) !== n.getAttribute(attr2);
});
// или
for (const { style, dataset } of elements) {
style.display = dataset[key1] === dataset[key2] ? 'block' : 'none';
}
// или (в стили надо будет добавить .hidden { display: none; })
for (let i = 0; i < elements.length; i++) {
const { classList: c, attributes: a } = elements[i];
c.toggle('hidden', a[attr1].value !== a[attr2].value);
}
:options="{ scrollWheelZoom: false }"
@update:zoom="zoom = $event"
@wheel.native="onWheel"
methods: {
onWheel(e) {
if (e.deltaY < 0) {
this.zoom++;
e.preventDefault();
}
},
},
options: [
{
...
propToBeMultipliedByPrice: 'area',
},
{
...
propToBeMultipliedByPrice: 'perimeter',
},
],
{{ option.price * calc[option.propToBeMultipliedByPrice] }}
преобразовать
['a' => [11, 12], 'b' => [21, 22]]
в
[['a' => 11, 'b' => 12], ['a' =>21, 'b' => 22]]
12
из a
становится значением свойства b
, а 21
- наоборот? Опечатка? - наверное, в a
исходного массива лежат значения свойств a
результата, аналогично и с b
.array_map(fn($i) => array_combine(array_keys($arr), array_column($arr, $i)), array_keys(array_values($arr)[0]))
{{ dish[`title_${lang}`] }}
v-text="dish['title_' + lang]"
:text.prop="dish['title_'.concat(lang)]"
не корректно работает
data: () => ({
scroll: 0,
}),
computed: {
buttonClass() {
return что-то, зависящее от значения this.scroll;
},
},
created() {
const { body } = document;
const onScroll = () => this.scroll = body.scrollTop;
body.addEventListener('scroll', onScroll);
this.$on('hook:beforeDestroy', () => body.removeEventListener('scroll', onScroll));
},
<button :class="buttonClass"></button>
$('.price_min_max_btn').click(function() {
const min = +$('.price_min').val() || 0;
const max = +$('.price_max').val() || Infinity;
$('.item_block_filter')
.hide()
.filter(function() {
const price = +this.dataset.price;
return min <= price && price <= max;
})
.show();
});
<div v-for="(story, idx) in stories" :key="idx">
<div v-for="n in stories.hits" :key="n.objectID">
.then(this.dates.push(response['dates'] ) ),
.then(response => this.dates = response.data.dates)
// или
.then(response => this.dates.push(...response.data.dates))
Как в данном случае правильно сделать...
Структуру данных менять нельзя
computed: {
filteredDialogs() {
const { dialogs, search } = this;
return search
? dialogs.filter(n => n.fullname.includes(search))
: dialogs;
},
},
v-if="dialogs.length > 0" v-for="(dialog, index) in dialogs"
<ul class="chat--messages__wrapper" ref="messages">
this.$nextTick(() => {
const { messages } = this.$refs;
messages.scrollTop = messages.scrollHeight;
});
def countCarsByBrand(cars, brands):
return sum(len(v.keys()) for k, v in cars.items() if k in brands)
print(countCarsByBrand(cars, [ 'Audi', 'BMW' ]))
attributes: [], // наполняется посредством rest API
props: [ 'value' ]
; а при необходимости его обновить отдаёт наверх новый массив: this.$emit('input', this.value.map(...))
. Это позволит использовать на компоненте директиву v-model
: <attributes-list v-model="attributes" />
.document.getElementById(selector).checked = true;
$emit
:methods: {
update(attr, checked) {
this.$emit('input', this.value.map(n => n === attr
? { ...n, checked }
: n
));
},
},
<div v-for="n in value">
<input type="checkbox" :checked="n.checked" @input="update(n, $event.target.checked)">
<button @click="update(n, true)">Да</button>
<button @click="update(n, false)">Нет</button>
</div>
v-model
на чекбоксах, то можно собрать объект вида { 'имя/id/ещё что-то уникальное': checked }
и завернуть его в Proxy:computed: {
attributes() {
return new Proxy(Object.fromEntries(this.value.map(n => [ n.name, n.checked ])), {
set: (target, key, val) => {
this.$emit('input', this.value.map(n => n.name === key
? { ...n, checked: val }
: n
));
return true;
},
});
},
},
<div v-for="(v, k) in attributes">
<input type="checkbox" v-model="attributes[k]">
<button @click="attributes[k] = true">Да</button>
<button @click="attributes[k] = false">Нет</button>
</div>