class App extends React.Component {
state = {
items: [...Array(20).keys()],
chunkLen: 3,
}
onClick = ({ target: { dataset: { change } } }) => {
this.setState(({ chunkLen }) => ({
chunkLen: Math.max(2, Math.min(9, chunkLen + +change)),
}));
}
render() {
const { items, chunkLen } = this.state;
const chunks = Array.from(
{ length: Math.ceil(items.length / chunkLen) },
(n, i) => items.slice(i * chunkLen, (i + 1) * chunkLen)
);
return (
<div>
<button data-change="-1" onClick={this.onClick}>-</button>
{chunkLen}
<button data-change="+1" onClick={this.onClick}>+</button>
<div>
{chunks.map(chunk => (
<div className="group">
{chunk.map(n => <div className="group-item">{n}</div>)}
</div>
))}
</div>
</div>
);
}
}
:data="chartData"
computed: {
chartData() {
return this.$store.getters.filterManagersChart.map(n => ({
name: n,
data: 53,
}));
},
},
class App extends React.Component {
state = {
items: Array.from({ length: 10 }, (n, i) => ({
id: i + 1,
value: String.fromCharCode(97 + i).repeat(5),
})),
active: [],
}
toggleActive = e => {
const id = +e.target.dataset.id;
this.setState(({ active }) => ({
active: active.includes(id)
? active.filter(n => n !== id)
: [ ...active, id ],
}));
}
render() {
const { items, active } = this.state;
return (
<ul>
{items.map(n => (
<li
key={n.id}
data-id={n.id}
onClick={this.toggleActive}
className={active.includes(n.id) ? 'active' : ''}
>
{n.value}
</li>
))}
</ul>
);
}
}
undefined
относится к falsy значениям, так что с помощью оператора ||
подставляйте пустой объект (или какое-нибудь другое значение - смотрите сами, как вам удобнее) там, где нужное значение может отсутствовать, например:(((lead._embedded.items[0].custom_fields.find(cf => cf.id == PRODUCT_FIELD_ID) || {}).values || {})[0] || {}).value || null
lead._embedded.items[0].custom_fields.find(cf => cf.id == PRODUCT_FIELD_ID)?.values[0].value ?? null
$count = array_count_values($arr);
$arr = array_filter($arr, function($n) use($count) {
return $count[$n] < 2;
});
$count = array_count_values($arr);
$arr = array_unique(array_filter($arr, function($n) use($count) {
return $count[$n] % 2;
}));
const elems = document.querySelectorAll('.fruits');
elems.forEach((n, i) => n.append(arr[i]));
// или
for (const [ i, n ] of elems.entries()) {
n.innerText = arr[i];
}
// или
for (let i = 0; i < elems.length; i++) {
elems[i].textContent = arr[i];
}
// или
(function next(i, n = elems.item(i)) {
if (n) {
n.appendChild(document.createTextNode(arr[i]));
next(i + 1);
}
})(0);
print(list(filter(lambda n: n % 10 in (2, 3, 4, 5), range(100))))
print([n for n in range(100) if n % 10 in (2, 3, 4, 5)])
print([m + n * 10 for n in range(10) for m in range(2, 6)])
watch: {
measureSystem: {
immediate: true,
handler() {
// сюда переносите код из mounted - axios.get(...)
},
},
},
computed: {
measureSystem() {
return this.toggle === 1 ? 'metric' : 'Imperial';
},
},
$(window).scroll(function onScroll() {
if ($(this).scrollTop() > 777) {
$('.div_clone').clone().appendTo('.container2');
$(this).off('scroll', onScroll);
}
});
rectPath = `M0 0 v${vert} h${horz} v${-vert} h${-horz}`
cellPath = ([ x, y ]) => `M${offset(x)} ${offset(y)} h${side} v${side} h${-side} v${-side}`
const isAllUnique = (...args) => new Set(args).size === args.length;
console.log(isAllUnique(69, 187, 666)); // true
console.log(isAllUnique(2, 2, 3, 4)); // false
console.log(isAllUnique(...'ABCDA')) // false
Допустимо ли использовать defs внутри symbol в SVG-элементе?
А тег style?
Где можно почитать о таких нюансах?
<input @change="doSomethingWithValue" />
methods: {
doSomethingWithValue(e) {
const value = e.target.value;
...
<input @change="doSomethingWithValue($event, 'hello, world!!')" />
$newData = array_map(function($item) {
return array_map(function($val) {
return [ 'text' => $val ];
}, array_values($item));
}, $data);
Проблема в том, что рисуется только последний график. Почему?
main.innerHTML += str;
main.insertAdjacentHTML('beforeend', str);
const canvas = document.createElement('canvas');
main.appendChild(canvas);
$('.nav').on('click', '[href="#id-3"]', function() {
$('.slick').slick('slickGoTo', 3);
});