const editTodo = (id, title) => {
setTodos(todos.map(n => n.id === id
? { ...n, title }
: n
));
};
function TodoItem({ complete, title, id, removeTodo, toggleTodo, editTodo }) {
const [ isEdit, setIsEdit ] = useState(false);
const [ editValue, setEditValue ] = useState('');
return (
<div className="todo-item">
<input type="checkbox" checked={complete} onChange={() => toggleTodo(id)} />
{isEdit
? <>
<input value={editValue} onChange={e => setEditValue(e.target.value)} />
<button onClick={() => (setIsEdit(false), editTodo(id, editValue))}>Save</button>
<button onClick={() => setIsEdit(false)}>Cancel</button>
</>
: <span onDoubleClick={() => (setIsEdit(true), setEditValue(title))}>{title}</span>
}
<button onClick={() => removeTodo(id)}>X</button>
</div>
);
}
const obj = {
a: {
b: {
c: {
xxx: 666,
},
},
},
};
const proxy = new Proxy(obj, {
get(target, key) {
return key.split('.').reduce((p, c) => p?.[c], target);
},
set(target, key, val) {
const keys = key.split('.');
const k = keys.pop();
keys.reduce((p, c) => p[c] ??= {}, target)[k] = val;
return true;
},
});
console.log(proxy['a.b.c.xxx']); // 666
proxy['x.y.z'] = 187;
console.log(obj.x.y.z); // 187
// имена свойств можно передавать в виде массива
const pick = (obj, keys) => Object.fromEntries(keys.map(n => [ n, obj[n] ]));
const newObj = pick(obj, [ 'b', 'c' ]);
// или как отдельные значения
const pick = (obj, ...keys) => keys.reduce((acc, n) => (acc[n] = obj[n], acc), {});
const newObj = pick(obj, 'b', 'c');
const pickExisting = (obj, keys) =>
Object.fromEntries(keys.filter(n => n in obj).map(n => [ n, obj[n] ]));
const pickOwn = (obj, keys) =>
keys.reduce((acc, n) => (Object.hasOwn(obj, n) && (acc[n] = obj[n]), acc), {});
const pick = (obj, filterFn) => Object.fromEntries(Object.entries(obj).filter(filterFn));
const obj1 = pick(obj, ([ k, v ]) => 'abc'.includes(k) && v % 2); // {a: 1, c: 3}
const obj2 = pick(obj, n => n[1] > 2); // {c: 3, d: 5}
$toStr = fn($arr) => implode('', array_map(fn($k) => "[$k:]$arr[$k][:$k]", array_keys($arr)));
print_r(array_map($toStr, $lang));
data: () => ({
meetupId: null,
meetupData: null,
}),
watch: {
meetupId(val) {
fetch(`https://course-vue.javascript.ru/api/meetups/${val}`)
.then(r => r.json())
.then(r => this.meetupData = r);
},
},
<label v-for="i in 5">
<input type="radio" name="meetupId" :value="i" v-model="meetupId">
{{ i }}
</label>
<pre>{{ meetupData }}</pre>
nextSlide() {
---> nextSlide = () => {
.onclick = this.nextSlide;
---> .onclick = () => this.nextSlide();
.onclick = this.nextSlide;
---> .onclick = this.nextSlide.bind(this);
this
. str.split(/(?<=\S)\s*(?=[А-ЯЁ])/).join(' ')
// или
str.replace(/(?<=\S)(?=[А-ЯЁ])/g, ' ')
// или
str.replace(/(\S)(?=[А-ЯЁ])/g, '$1 ')
// или
str.replace(/[А-ЯЁ]/g, (m, i) => i && str[~-i] !== ' ' ? ' ' + m : m)
почему ошибку выдает?
It should take an array of numbers as its argument and return the two highest numbers within the array.
function twoOldestAges($ages) {
sort($ages);
return array_slice($ages, -2);
}
function twoOldestAges($ages) {
$a = -INF;
$b = -INF;
foreach ($ages as $n) {
if ($n > $a) {
$b = $a;
$a = $n;
} else if ($n > $b) {
$b = $n;
}
}
return [ $b, $a ];
}
function search(nums, target, searchMin) {
for (let iMin = 0, iMax = nums.length - 1; iMin <= iMax; ) {
const index = (iMin + iMax) / 2 | 0;
const num = nums[index];
if (num === target && num !== nums[index + (searchMin ? -1 : 1)]) {
return index;
} else if (num <= target - (searchMin ? 1 : 0)) {
iMin = index + 1;
} else {
iMax = index - 1;
}
}
return -1;
}
function searchMinMax(nums, target) {
const iMin = search(nums, target, true);
return iMin === -1
? []
: [ iMin, search(nums, target, false) ];
}
@update:modelValue="$emit('change', $event.target.value)"
update:modelValue
?@change="$emit('update:modelValue', $event.target.value)"
model: { prop: 'modelValue', event: 'update:modelValue' },
BREAKING:v-bind
's.sync
modifier and componentmodel
option are removed and replaced with an argument on v-model;
.filter(function (el, i) { return arr[i] === el[i]; })
0
? Или 5
? А зачем тогда [i]
? Может, должно было быть arr[i] === el
? const dashoffset = circleRef.current - ...
NaN
.const getSctollTop = () => { return window.pageYOffset || document.documentElement.scrollTo; }
scrollTo
? Это же метод, а вы вроде бы число хотите получить. Может, scrollTop
?React.useEffect(() => { ... window.addEventListener("scroll", () => { ... }); }, []);
Как должен выглядеть json...
[
{
title: '...',
children: [
{
title: '...',
children: [
{
title: '...',
},
...
],
},
...
],
},
...
]
...для генерации такого вложенного списка через v-for?
name: 'v-tree',
props: [ 'items' ],
<ul v-if="Array.isArray(items) && items.length">
<li v-for="n in items">
{{ n.title }}
<v-tree :items="n.children" />
</li>
</ul>
const popup =createApp(App);
popup.$store.dispatch
$store
, вам нужен результат вызова mount
, а не createApp
.store.dispatch
. const searchOptions = [
[ '#search_table', tr => $('input[name^=name]', tr).val() ],
[ '#search_card', tr => $('[data-item-name="name"]', tr).text() ]
];
$(searchOptions.map(n => n[0]).join(', ')).on('input', () => {
const values = searchOptions.map(n => $(n[0]).val().toLowerCase());
$('#tabname tbody tr')
.hide()
.filter((i, n) => searchOptions.every((m, j) => m[1](n).toLowerCase().includes(values[j])))
.show();
});