localStorage.setItem('reorder', JSON.stringify(this.reorder));
this.reorder = JSON.parse(localStorage.getItem('reorder')) || [];
i.
на active.
. Условие рендеринга окна станет v-if="active"
. Обработчик клика кнопки закрытия окна: @click="active = null"
. Обработчик клика на изображение внутри v-for: @click="active = i"
. data: () => ({
goals: [
{
name: '...',
tasks: [
{ name: '...', value: 0 },
{ name: '...', value: 0 },
...
],
},
...
],
}),
methods: {
getValues(tasks, task) {
const max = 100 - tasks.reduce((acc, n) => acc + n.value, -task.value);
return [ 0, 10, 20, 30, 40, 50, 60 ].filter(n => n <= max);
},
},
<tr v-for="g in goals">
<td>{{ g.name }}</td>
<td>
<div v-for="t in g.tasks" class="task">
{{ t.name }}
<select v-model.number="t.value">
<option v-for="v in getValues(g.tasks, t)" :value="v">{{ v }}</option>
</select>
</div>
</td>
</tr>
в обычном html файле
<script src="vue-date-pick-master/dist/vueDatePick.js"></script>
<link href="vue-date-pick-master/dist/vueDatePick.css" rel="stylesheet">
components: {
VueDatePick,
},
Vue.component('date-pick', VueDatePick);
function setNestedValue(root, ...args) {
const val = args.pop();
const key = (args = args.join('.').split('.')).pop();
args.reduce((p, c) => p[c] = p[c] || {}, root)[key] = val;
}
const obj = {};
setNestedValue(obj, 'xxx', 'yyy', 'zzz', 69);
setNestedValue(obj, 'xxx.a.b.c', 187);
setNestedValue(obj, '_', 666);
function mergeIntervals(intervals) {
intervals = intervals.map(n => [...n]);
if (intervals.length < 2) {
return intervals;
}
intervals.sort((a, b) => a[0] - b[0]);
const stack = [];
intervals.forEach(n => {
const top = stack[stack.length - 1];
if (!top || top[1] < n[0]) {
stack.push(n);
} else if (top[1] < n[1]) {
top[1] = n[1];
}
});
return stack;
}
$groups = [];
foreach ($data as $item) {
$groups[$item['title']][] = $item;
}
echo implode('', array_map(function($group, $title) {
$items = implode('', array_map(function($item) {
$name = $item['name'];
return "<div>$name</div>";
}, $group));
return "<h4>$title:</h4>$items";
}, $groups, array_keys($groups)));
Не могу понять как правильно написать цикл перебора.
$('.hello').attr('data-class', function() {
return [...this.classList].filter(n => n !== 'hello');
});
document.querySelectorAll('.hello').forEach(n => {
n.dataset.class = n.className.replace(/(^| )hello( | $)/, ' ').trim();
});
$('.hello').attr('data-class', function() {
return this.classList[1];
});
document.querySelectorAll('.hello').forEach(n => {
n.dataset.class = n.className.split(' ').pop();
});
Array.prototype.push.apply(
arr,
newArr.filter(n => !arr.some(m => m.trade_id === n.trade_id))
);
const pushDiff = (target, source, key = n => n) =>
target.push(...source.filter(function(n) {
return !this.has(key(n));
}, new Set(target.map(key))));
pushDiff(arr, newArr, n => n.trade_id);
Пробовал через массивы, но не работает.