...как мне правильно написать регулярку для jq метода find(), чтобы он...
data: () => ({
items: [...Array(5).keys()],
}),
methods: {
move(index, step) {
const items = [...this.items];
const newIndex = Math.min(items.length - 1, Math.max(0, index + step));
[ items[index], items[newIndex] ] = [ items[newIndex], items[index] ];
this.items = items;
},
// или
move(index, step) {
const { items } = this;
const newIndex = Math.min(items.length - 1, Math.max(0, index + step));
items.splice(index, 1, items.splice(newIndex, 1, items[index])[0]);
},
// или
move(index, step) {
const newIndex = Math.min(this.items.length - 1, Math.max(0, index + step));
if (index !== newIndex) {
const val = this.items[index];
this.$set(this.items, index, this.items[newIndex]);
this.$set(this.items, newIndex, val);
}
},
},<div v-for="(n, i) in items">
<input v-model="items[i]">
<button @click="move(i, -1)">вверх</button>
<button @click="move(i, +1)">вниз</button>
</div>
не получается обратиться к геттеру <...> показывает null, хотя если вызвать store.getters, то данные есть
<компонент v-if="$store.getters.profile" />//Подключаю хранилище import store from './store'; store.dispatch('getUser'); new Vue({ el: '#app', router: router, components:{ 'head-app':headImplant, 'footer-app':footer, 'sidebar-app': sidebar } });
new Vue({
store,
...
class App extends Component {
state = {
users: []
}
componentDidMount() {
fetch('https://jsonplaceholder.typicode.com/users')
.then(response => response.json())
.then(users => this.setState({ users }));
}
render() {
return(
<div className="App">
<table>
<tbody>
{this.state.users.map(n => (
<tr key={n.id}>
<td>{n.name}</td>
<td>{n.username}</td>
<td>{n.email}</td>
<td>{n.website}</td>
</tr>
))}
</tbody>
</table>
</div>
)
}
}
<select id="person"></select>
<select id="key"></select>
<span id="value"></span>const data = [
{
"ФИО": "Иванов Сергей",
"Адрес": {
"Город": "Москва",
"Улица": "Пятницкая",
"Дом": "35",
},
},
{
"ФИО": "Сидоров Иван",
"Адрес": {
"Город": "Питер",
"Улица": "Ленина",
"Дом": "42",
},
},
];
const selects = [
Select('#person', data.map(n => n['ФИО'])),
Select('#key', Object.keys(data[0]['Адрес'])),
];
selects.forEach(n => n.addEventListener('change', onChange));
function Select(selector, options) {
const el = document.querySelector(selector);
el.append(...options.map(n => new Option(n)));
el.value = null;
return el;
}
function onChange() {
const [ person, key ] = selects.map(n => n.value);
if (person && key) {
const value = data.find(n => n['ФИО'] === person)['Адрес'][key];
document.querySelector('#value').textContent = value;
}
}
v-if="accounts" и v-if="transactions" тем блокам, внутри которых рендерятся элементы на основе соответствующих свойств.
Является ли нормальной практикой создание нового метода , включающего в себя эти три метода
buildButton(() => {
this.drawSomeButtons();
this.changeSomeVariables();
this.doSomethingElse();
});
x - свойство экземпляра, другой - статический геттер:class Base {
constructor() {
this.x = 3;
}
static get x() {
return 1.5;
}
}function Base() {
this.x = 3;
}
Base.x = 1.5;
// или
function Base() {}
Base.prototype.x = 3;
Base.x = 1.5;class Base {
x = 3;
static x = 1.5;
}
this.steppers[index]=this.steppers[index]+this.step_gothis.$set(this.steppers, index, this.steppers[index] + this.step_go)
$str = "философски нагруженная";
preg_match("/.{50}$str.{50}/u", $text, $match);
const getValue = (obj, index = 0) =>
Object.values(obj)[index];function getValue(obj, index = 0) {
for (const k in obj) {
if (obj.hasOwnProperty(k) && !index--) {
return obj[k];
}
}
}
$('.list_add_room').on('click', '.butt_edit', function() {
const $el = $(this).closest('.item_contain_list').find('p');
$('.list_add_room [contenteditable="true"]').not($el).removeAttr('contenteditable');
$el.attr('contenteditable', (i, val) => val !== 'true').focus();
});$('.list_add_room').on('click', '.butt_edit', function() {
$(this).closest('.item_contain_list').find('p').attr('contenteditable', 'true').focus();
}).on('blur', '[contenteditable="true"]', function() {
$(this).removeAttr('contenteditable');
});