const LENGTH = чему-то там равно, это вам виднее;
const input = document.querySelector('селектор инпута');
const button = document.querySelector('селектор кнопки');
input.addEventListener('input', e => {
button.style.display = e.target.value.length >= LENGTH ? '' : 'none';
});
input.dispatchEvent(new Event('input'));
я меняю другие данные
this.type === 'columns'
? this.items.slice(1).map(n => ({ ...n }))
: []
if (typeof defaultBg1 == 'Background') // ???
null
и undefined
свойств не бывает, попытка обратиться к конструктору в их случае приведёт к TypeError
; кроме того, instanceof
проверяет всю цепочку прототипов, т.е., например, [ 1, 2, 3 ]
одновременно и instanceof Array
, и instanceof Object
):if (defaultBg1 instanceof Background)
// или
if (defaultBg1.constructor === Background)
// или
if (defaultBg1.constructor.name === 'Background')
const type = x => x == null ? `${x}` : x.constructor.name;
type() // 'undefined'
type(null) // 'null'
type(true) // 'Boolean'
type(69) // 'Number'
type('hello, world!!') // 'String'
type(/./) // 'RegExp'
type([ 187 ]) // 'Array'
type({ z: 666 }) // 'Object'
type(document) // 'HTMLDocument'
type(document.querySelectorAll('div')) // 'NodeList'
type(new class XXX {}) // 'XXX'
type(type) // 'Function'
chartObj: Chart;
this.chartObj = new Chart(reportCtx, ...
this.chartObj.data.datasets
this.chartObj.update();
нужно при клике на беседу отображать все сообщения и нужную информацию
Можно ли как-то заставить Vue заменять весь контент?
Немного недопонял, можешь продемонстрировать как это задать?
data: () => ({
devices: [],
}),
this.devices = Object.entries(res.data).map(([ id, n ]) => ({ ...n, id }));
<ul>
<li v-for="d in devices" :key="d.id">
...
function getRootItem($id, $array) {
foreach ($array as $item) {
if ($item['id'] === $id) {
$parent = $item['parent'];
return $parent === 0 ? $item : getRootItem($parent, $array);
}
}
return null;
}
const getDateOfNearestDay = (day, date = new Date()) =>
new Date(
date.getFullYear(),
date.getMonth(),
date.getDate() + ((7 + day - date.getDay()) % 7)
);
const dateOfNearestSaturday = getDateOfNearestDay(6);
получаю ошибку
вызываю в дочернем компоненте this.props.getCity(1, 'П')
getCity={this.getCity}
, при этом метод getCity в родительском компоненте отсутствует. Есть getCities. Это как?передается пустой токен
{this.state.token && <NewAdvert id="newadvert"
user={this.state.fetchedUser}
cities={this.cities}
getCities={this.getCities}
getCity={this.getCity}
token={this.state.token}
getToken={this.getToken}
go={this.go}
/>}
Предполагается, что когда пользователь нажмет на фильтр, у меня вызовется функция setRouter...
.push(item)
на .push(+item)
(или .push(Number(item))
, или .push(parseInt(item))
). Соответственно, надо сделать числом и search - для этого достаточно добавить соответствующий модификатор v-model..sort()
на .sort((a, b) => a - b)
.computed: {
array() {
return this.info
.split(';')
.map(n => parseInt(n))
.filter(n => !Number.isNaN(n))
.sort((a, b) => a - b);
},
},
const values = Object.values(arr.reduce((acc, n) => {
const t = acc[n.from];
acc[n.from] = (t && t.to > n.to) ? t : n;
return acc;
}, {})).map(n => n.val);
const values = Object.values(arr.reduce((acc, n) => {
(acc[n.from] = acc[n.from] || [])[n.to] = n.val;
return acc;
}, {})).map(n => n.pop());
const values = [...arr]
.sort((a, b) => (a.from - b.from) || (a.to - b.to))
.filter((n, i, a) => !a[i + 1] || a[i + 1].from !== n.from)
.map(n => n.val);
Можно с помощью lodash.
const values = _
.chain(arr)
.groupBy('from')
.map(n => _.maxBy(n, m => m.to).val)
.value();