groupedItems() {
return this.items.reduce((acc, n) => {
for (const k in n) {
acc[k] = acc[k] || {};
acc[k][n[k]] = (acc[k][n[k]] || 0) + 1;
}
return acc;
}, {});
}
<div v-for="(group, groupName) in groupedItems">
<h3>{{ groupName }}:</h3>
<div v-for="(value, key) in group">{{ key }} ({{ value }})</div>
</div>
import MyCalendar from './MyCalendar';
import { MyCalendar } from './MyCalendar';
methods: {
onClick1() {
alert('button1 clicked');
},
onClick2() {
this.$refs.button.click();
},
},
<button @click="onClick1" ref="button">button1: click me</button>
<button @click="onClick2">button2: click button1</button>
JSON.stringify(user, (k, v) => v instanceof Function ? v.toString() : v)
ng-controller="plantCtrl"
. data: () => ({
active: null,
items: [
{ text: 'hello, world!!', numSpans: 3, classes: [] },
{ text: 'fuck the world', numSpans: 6, classes: [ 'yyy' ] },
{ text: 'fuck everything', numSpans: 0, classes: [ 'zzz' ] },
],
}),
<ul>
<li v-for="(n, i) in items" :class="{ active: active === i }">
<a :class="[ 'xxx', ...n.classes ]" @click="active = i">
{{ n.text }}
<span v-for="s in n.numSpans"></span>
</a>
</li>
</ul>
.active {
background: red;
}
this.setState(newState, () => {
// вот здесь
})
.catch(this.handleError)
.catch(err => this.handleError(err))
const result = [];
for (const n of elements) {
if (!used.some(m => m.id === n.id)) {
result.push(n);
}
}
const result = [];
COLLECT_OBJECTS:
for (let i = 0; i < elements.length; i++) {
for (let j = 0; j < used.length; j++) {
if (elements[i].id === used[j].id) {
continue COLLECT_OBJECTS;
}
}
result[result.length] = elements[i];
}
const result = elements.filter(function(n) {
return !this.has(n.id);
}, new Set(used.map(n => n.id)));
const result = (function get(ids, i, n = elements[i]) {
return n
? [].concat(ids.includes(n.id) ? [] : n, get(ids, -~i))
: [];
})(used.map(n => n.id), 0);
const result = [...used.reduce(
(acc, n) => (acc.delete(n.id), acc),
new Map(elements.map(n => [ n.id, n ]))
).values()];
$.getJSON('https://api.cdnjs.com/libraries/jquery', function(data) {
$('body').append(`<pre>${JSON.stringify(data, null, 2)}</pre>`);
});
const toHTML = val =>
val instanceof Object
? `<ul>${Object.values(val).map(n => `
<li>${toHTML(n)}</li>`).join('')}
</ul>`
: val;
fetch('https://api.cdnjs.com/libraries/jquery')
.then(r => r.json())
.then(r => document.body.insertAdjacentHTML('beforeend', toHTML(r)));
this.setState({ price: this.state.price + price, title: [this.state.title+title]});
this.setState({
price: this.state.price + price,
title: this.state.title.concat(title)
});
str_replace($alphabet, array_keys($alphabet), $str)