const inputs = document.querySelectorAll('form input');
// или
const inputs = document.forms[0].elements;
// или
const inputs = document.querySelector('form').getElementsByTagName('input');
const getName = el => el.name;
// или
const getName = el => el.getAttribute('name');
// или
const getName = el => el.attributes.name.value;
const names = Array.from(inputs, getName);
// или
const names = Array.prototype.map.call(inputs, getName);
// или
const names = [];
for (const n of inputs) {
names.push(getName(n));
}
// или
const names = [];
for (let i = 0; i < inputs.length; i++) {
names[i] = getName(inputs[i]);
}
activeProjects.map((project, i) => { <div key={i} className="focus-projects">
render() {
const activeProjects = this.props.projects.filter(n => n.ProjectStatus === 'ACTIVE');
...
const result = Object
.entries(arr.reduce((acc, n, i) => ((acc[n] = acc[n] || []).push(i), acc), {}))
.map(([ label, indexes ]) => indexes.length > 1 ? { label, indexes } : label);
const result = Object.values(arr.reduce((acc, n) => (
(acc[n.ID] = acc[n.ID] || { ID: n.ID })[n.FIELD] = n.VALUE,
acc
), {}));
setInterval(count => {
const
len = count.length,
val = `${+count.map(n => n.textContent).join('') + 1}`.padStart(len, 0).slice(-len);
count.forEach((n, i) => n.textContent = val[i]);
}, 50, [...document.querySelectorAll('.count')]);
$grouped = [];
foreach ($arr as $n) {
$id = $n['User_ID'];
$grouped[$id] = $grouped[$id] ?? $n;
$grouped[$id]['arrGorodVievs'] += $n['arrGorodVievs'];
}
document.querySelectorAll('div[name] ul[name]').forEach(n => {
if (n.getAttribute('name') !== n.closest('div[name]').getAttribute('name')) {
n.remove();
}
});
for (const n of document.querySelectorAll('div[name]')) {
for (const m of n.querySelectorAll(`ul:not([name="${n.attributes.name.value}"])`)) {
m.parentNode.removeChild(m);
}
}
class App extends Component {
state = {
options: [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry", isDisabled: true },
{ value: "vanilla", label: "Vanilla" },
],
}
render() {
return (
<Select
options={this.state.options}
/>
);
}
}
class App extends Component {
state = {
options: [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" }
],
disabled: [ 'chocolate', 'vanilla' ],
}
isOptionDisabled = option => this.state.disabled.includes(option.value)
render() {
return (
<Select
options={this.state.options}
isOptionDisabled={this.isOptionDisabled}
/>
);
}
}
class App extends React.Component {
state = {
rates: {
RUB: 1,
},
currency: 'RUB',
currencies: [
{ name: 'RUB', label: 'RUB' },
{ name: 'USD', label: 'USD' },
{ name: 'EUR', label: 'EUR' },
],
}
onCurrencyChange = ({ target: { dataset: { currency } } }) => {
this.setState({ currency });
}
componentDidMount() {
fetch('https://www.floatrates.com/daily/rub.json')
.then(res => res.json())
.then(data => {
this.setState(({ rates }) => ({
rates: {
...rates,
...Object.values(data).reduce((acc, n) => (acc[n.code] = n.rate, acc), {}),
},
}));
});
}
render() {
const { currency, currencies, rates } = this.state;
return (
<div>
{currencies.map(({ name, label }) => (
<button
className={`btn__item ${currency === name ? 'active' : ''}`}
data-currency={name}
onClick={this.onCurrencyChange}
>
{label}
</button>
))}
{this.props.products.map(({ name, price }) => (
<div>
<span>{name}</span>
<span>{(price * rates[currency]).toFixed(2)} {currency}</span>
</div>
))}
</div>
);
}
}
const products = [
{ name: 'яблоки', price: '80' },
{ name: 'греча', price: '50' },
{ name: 'конфеты', price: '380' },
];
ReactDOM.render(<App products={products} />, document.getElementById('root'));
Серьезно?)) router-view у меня в App
router-view
. display: flex
и вешайте ему класс, который будет переопределять order
у дочерних элементов. const sorted = (arr, key) => arr
.map(n => [ n, key(n) ])
.sort((a, b) => a[1] - b[1])
.map(n => n[0]);
// если элементы с отсутствующим номером квартиры должны оказаться
// в начале, а не в конце, то вместо Infinity надо поставить 0
const sortedArr = sorted(arr, n => +(n.address.match(/кв.\s*(\d+)/) || [ Infinity ]).pop());
$numArr = count($array);
$numElems = count($array[0]);
$combinations = [];
$numCombinations = pow($numElems, $numArr);
for ($i = 0; $i < $numCombinations; $i++) {
$combination = [];
for ($j = 0; $j < $numArr; $j++) {
$arrIndex = $j;
$elIndex = $i / pow($numElems, $j) % $numElems;
$combination[] = $array[$arrIndex][$elIndex];
}
$combinations[] = $combination;
}