const getAndDel = (obj, ...keys) =>
keys.reduce((acc, n) => (
acc[n] = obj[n],
delete obj[n],
acc
), {});
const obj1 = { a: 1, b: 2, c: 3, d: 4 };
const obj2 = getAndDel(obj1, 'a', 'b');
const obj3 = getAndDel(obj1, 'c');
console.log(obj1); // {d: 4}
console.log(obj2); // {a: 1, b: 2}
console.log(obj3); // {c: 3}
появляется ошибка в консоли <...> Functions are not valid as a React child.
{this.countPrice}
. А надо {this.countPrice()}
. Ну или сделайте countPrice геттером.countPrice = () => {
return this.state.productsList.reduce((acc, n) => acc + n.price, 0);
}
if(axis === "x") ctx.moveTo((position + x0), yMax); ctx.lineTo((position + x0), (y0 - dec)); ctx.stroke(); if(axis === "y") ctx.moveTo(x0, (yMax - position)); ctx.lineTo(xMax, (yMax - position)); ctx.stroke();
this.insertAdjacentHTML('afterend', `
<select>${arr.map(n => `
<option value="${n.value}" ${n.selected ? 'selected' : ''}>
${n.text}
</option>`).join('')}
</select>
`);
const select = document.createElement('select');
arr.forEach(n => select.appendChild(Object.assign(document.createElement('option'), n)));
this.insertAdjacentElement('afterend', select);
const select = document.createElement('select');
select.append(...arr.map(n => new Option(n.text, n.value, false, n.selected)));
this.after(select);
array_walk_recursive($arr, function(&$val, $key) {
$val = trim($val);
});
const getWidths = data =>
[].concat(data || []).reduce((acc, n) => {
if (n.hasOwnProperty('width')) {
acc.push(n.width);
}
acc.push(...getWidths(n.columns));
return acc;
}, []);
function getDatesIntervalStr(dates) {
const dateParts = d => ({ year: d.year(), month: d.format('MMMM') });
const start = dateParts(dates[0]);
const end = dateParts(dates[dates.length - 1]);
if (start.year !== end.year) {
return `${start.month} ${start.year} - ${end.month} ${end.year}`;
} else if (start.month !== end.month) {
return `${start.month} - ${end.month} ${end.year}`;
} else {
return `${end.month} - ${end.year}`;
}
}
data: () => ({
selected: [],
}),
methods: {
key: (x, y) => `${y}.${x}`,
select({ buttons, target: { dataset: { key } } }) {
if (buttons) {
const index = this.selected.indexOf(key);
if (index !== -1) {
this.selected.splice(index, 1);
} else {
this.selected.push(key);
}
}
},
},
<table>
<tr v-for="y in 10">
<td
v-for="x in 10"
@mousedown="select"
@mouseover="select"
:data-key="key(x, y)"
:class="{ selected: selected.includes(key(x, y)) }"
>{{ key(x, y) }}</td>
</tr>
</table>
data: () => ({
items: [...Array(10)].map(() => Array(10).fill(false)),
}),
methods: {
select(row, index, e) {
if (e.buttons) {
this.$set(row, index, !row[index]);
}
},
},
<table>
<tr v-for="(row, y) in items">
<td
v-for="(cell, x) in row"
@mousedown="select(row, x, $event)"
@mouseover="select(row, x, $event)"
:class="{ selected: cell }"
>{{ y + 1 }}.{{ x + 1 }}</td>
</tr>
</table>
transition-group
, у отдельных элементов списка анимируем высоту (должна быть задана).Тут сама сложность в том чтоб сделать бордер.
chart: {
events: {
click() {
this.update({
yAxis: {
breaks: новое значение для breaks,
},
});
},
},
},
<div class="colors">
<div class="color" data-color="blue">Blue</div>
<div class="color" data-color="red">Red</div>
<div class="color" data-color="pink">Pink</div>
</div>
let selectedTD = null;
const $colors = $('.colors').on('click', '.color', function() {
$(selectedTD).css('backgroundColor', this.dataset.color);
selectedTD = null;
$colors.hide();
}).hide();
$('table').on('click', 'td', function() {
selectedTD = selectedTD === this ? null : this;
$colors.toggle(!!selectedTD);
});
...или есть какой-то скрытый от меня смысл?
It will handle cases withSymbol.toPrimitive
correctly and throw correctly if template literal expression is aSymbol()
. See babel/babel#5791.