const data = $('.price')
.filter((i, n) => +n.value)
.closest('tr')
.find('input[type="hidden"]')
.get()
.map(n => n.value);const data = Array
.from(document.querySelectorAll('.price'))
.filter(n => +n.value)
.map(n => n.closest('tr').querySelector('input[type="hidden"]').value);const data = Array.prototype.reduce.call(
document.getElementsByClassName('price'),
(acc, { value: v, parentNode: { parentNode: tr } }) => (
+v && acc.push(tr.cells[0].children[0].value),
acc
),
[]
);
Child components that havemetaInfowill recursively merge theirmetaInfointo the parent context, overwriting any duplicate properties.
Как можно решить эту проблему?
$num = 3.1415;
$sum = array_sum(array_slice(str_split(explode('.', $num)[1]), 2, 2));$num = 3.1415;
$idx = [ 1, 3, 5 ]; // индексы нужных цифр: 1 - это 4, 3 - это 5, 5 - этого уже нет, но ошибки не возникнет, будет использован 0
$digits = str_split(explode('.', $num)[1]);
$sum = array_reduce($idx, function($acc, $n) use($digits) {
return $acc + (isset($digits[$n]) ? $digits[$n] : 0);
}, 0);$num передавайте $num.'.'.
showFirstHideLast('table', 'tr', 3);.function showFirstHideLast(containerSelector, itemSelector, hideFrom) {
$(containerSelector).each((_, n) => {
$(itemSelector, n).show().slice(hideFrom).hide();
});
}function showFirstHideLast(containerSelector, itemSelector, hideFrom) {
document.querySelectorAll(containerSelector).forEach(n => {
n.querySelectorAll(itemSelector).forEach((m, i) => {
m.hidden = i >= hideFrom;
// или
m.style.display = i < hideFrom ? '' : 'none';
// или (в стили надо будет добавить .hidden { display: none; })
m.classList.toggle('hidden', i >= hideFrom);
});
});
}
когда оба поля заполнены нулями, необходимо выводить всю таблицу
(!min && !max).
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 setNested(root, ...args) {
const val = args.pop();
const key = (args = args
.flat(Infinity)
.flatMap(n => typeof n === 'string' ? n.split('.') : n))
.pop();
args.reduce((p, c) => p[c] = p[c] || {}, root)[key] = val;
}const obj = {};
setNested(obj, 'xxx', 'yyy', 'zzz', 69);
setNested(obj, 'xxx.a.b.c', 187);
setNested(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)));