$('[data-index]').click(function() {
$('#main__display').html(`<img src="${collect[this.dataset.index]}">`);
});
document.querySelectorAll('[data-index]').forEach(function(n) {
n.addEventListener('click', this);
}, function(e) {
this.innerHTML = `<img src="${collect[e.currentTarget.dataset.index]}">`;
}.bind(document.querySelector('#main__display')));
const THICKNESS = {
thinLine: 1,
get midLine() {
return this.thinLine * 2;
},
get boldLine() {
return this.thinLine * 4;
},
};
после 21 итерации выдает неправильное значение даты
const startDate = new Date(2019, 7, 11);
const currentDate = new Date(startDate);
for (let i = 0; i <= 30; i++) {
currentDate.setDate(currentDate.getDate() + 1);
console.log(currentDate);
}
const startDate = new Date(2019, 7, 11);
for (let i = 0; i <= 30; i++) {
const currentDate = new Date(startDate);
currentDate.setDate(startDate.getDate() + i);
console.log(currentDate);
}
Vue.set(this.response.order.ordersItemsInfo[id], 'ordersItemsPropertiesInfo', [])
data: () => ({
items: [ 'active1', 'active2', 'active3' ],
active: false,
}),
<button @click="active = !active"></button>
...
<div v-for="n in items" :class="{ [n]: active }"></div>
function createList(data) {
const list = document.createElement('ul');
const stack = [];
let level = +data[0].match(/\d+/);
let ul = list;
for (const n of data) {
const currLevel = +n.match(/\d+/);
if (currLevel > level) {
stack.push([ ul, level ]);
[ ul, level ] = [ document.createElement('ul'), currLevel ];
stack[stack.length - 1][0].lastElementChild.append(ul);
} else {
for (; currLevel !== level; [ ul, level ] = stack.pop()) ;
}
ul.insertAdjacentHTML('beforeend', `<li>${n}</li>`);
}
return list;
}
await setTimeout
await new Promise(r => setTimeout(r, 1000))
.catch((e)=>{this.handleUsersListErrors(e)})
data: () => ({
status: 'unknown',
val: 'empty',
}),
methods: {
getVal() {
this.status = 'awaiting request answer';
return new Promise((...r) => {
setTimeout(() => {
const max = 10000;
this.val = Math.random() * max | 0;
r[+(this.val < max * 0.9)]();
}, 1000);
}).catch(this.handleError);
},
handleError() {
this.status = 'ERROR, awaiting new request';
return new Promise(r => setTimeout(r, 2000)).then(this.getVal);
},
},
async created() {
await this.getVal();
this.status = 'OK';
},
<div>status: {{ status }}</div>
<div>value: {{ val }}</div>
изучаю метод фильтр
greater than or equal to 8.0
rating > 8
combination of filter and map
watchList.filter(n => n.imdbRating >= 8).map(n => ({ title: n.Title, rating: n.imdbRating }))
// или
watchList.reduce((acc, { Title: title, imdbRating: rating }) => (
rating < 8 || acc.push({ title, rating }),
acc
), [])
<div id="app"></div>
function App() {
const [ dark, setDark ] = React.useState(null);
const updateDark = e => setDark(e.type === 'mouseover' ? e.currentTarget.id : null);
return (
<React.Fragment>
{[ 'left', 'right' ].map(n => (
<div
id={n}
key={n}
onMouseOver={updateDark}
onMouseLeave={updateDark}
className={dark && dark !== n ? 'dark' : ''}
></div>
))}
</React.Fragment>
);
}
ReactDOM.render(<App />, document.getElementById('app'));