onChange = ({ target: { value, dataset: { objName, key } } }) => {
this.setState(({ [objName]: obj }) => ({
[objName]: {
...obj,
[key]: value,
},
}));
}
<input data-obj-name="fr" data-key="name" value={this.state.fr.name} onChange={this.onChange} />
<input data-obj-name="en" data-key="title" value={this.state.en.title} onChange={this.onChange} />
data: () => ({
repeat: 0,
}),
<child-component v-for="i in repeat"></child-component>
<button @click="repeat++">add one more child component instance</button>
const $table = $('table');
const columnIndex = // здесь должен быть номер столбца с числами
const sum = $table
.find('tr:visible')
.get()
.reduce((acc, n) => acc + +$('td', n).eq(columnIndex).text(), 0);
$table
.find('th')
.eq(columnIndex)
.text(`Вес (${sum})`);
class App extends React.Component {
state = {
cells: Array(16).fill(null),
probability: 0.7,
}
onClick = e => {
const index = +e.target.dataset.index;
this.setState(({ cells, probability }) => ({
cells: cells.map((n, i) => i === index && !n
? (Math.random() < probability ? 'black' : 'red')
: n
),
}));
}
render() {
return (
<div className="ColorS">
{this.state.cells.map((n, i) => (
<div
className="ColorS-grid"
style={n && { background: n }}
data-index={i}
onClick={this.onClick}
/>
))}
</div>
);
}
}
$('.news-block-2').each((i, n) => $('.text-news', n).after($('.picture-news', n)));
$('.news-block-2 tr').append(function() {
return $('.picture-news', this);
});
$('.news-block-2 .text-news').each((i, n) => $(n).parent().prepend(n));
$('.news-block-2 .picture-news').before(function() {
return $(this).next();
});
X = n => n ? (n & 1 ? '-chirp' : '') + X(n >> 1) + X(n >> 1) : ''
chirp = n => X(n).slice(1)
google.visualization.arrayToDataTable(data, true)
.el {
animation: blink 2s linear infinite;
background: #000;
}
.el:nth-child(1) { animation-delay: 0s; }
.el:nth-child(2) { animation-delay: 0.5s; }
.el:nth-child(3) { animation-delay: 1s; }
.el:nth-child(4) { animation-delay: 1.5s; }
@keyframes blink {
0%, 20% {
background: #000;
}
10% {
background: #F00;
}
}
function App() {
const [ items, setItems ] = useState([]);
const onItemClick = ({ target: { dataset: { id } } }) =>
setItems(items.filter(n => n !== +id));
const onAddNewClick = () =>
setItems([ ...items, 1 + Math.max(0, ...items) ]);
return (
<div>
{items.map(n => <button onClick={onItemClick} data-id={n}>#{n}</button>)}
<button onClick={onAddNewClick}>add</button>
</div>
);
}
data: () => ({
items: [ ... ], // массив данных
columns: 666, // количество колонок, на которые надо разбить items
}),
computed: {
columnItems() {
const { items, columns } = this;
const colSize = Math.ceil(items.length / columns);
return Array.from(
{ length: columns },
(n, i) => items.slice(i * colSize, (i + 1) * colSize)
);
},
},
<ul v-for="col in columnItems">
<li v-for="n in col">{{ n }}</li>
</ul>
<img v-for="i in 5" :src="i > ratingValue ? whiteStar : blackStar">
Array
.from(document.querySelectorAll('.obj'))
.filter(n => n.querySelector('.who')?.innerText !== 'Я')
.forEach(n => console.log(n.innerText));
const $items = $('.item');
const SLICE_SIZE = 3;
$('.container').append(i => $items.slice(i * SLICE_SIZE, (i + 1) * SLICE_SIZE));