const result = {};
const list = {
"action_buttons[0]": "View",
"action_buttons[1]": "Share",
"action_buttons[2]": "Download",
"columns[0]": "Date of Study",
"columns[1]": "Patient",
"columns[2]": "File name",
"columns[3]": "Reporting <br>Physician",
"columns[4]": "Institution"
};
Object.keys(list).forEach(key => {
const value = list[key];
const combinedKey = key.replace(/\[.+\]/, '');
if (Array.isArray(result[combinedKey])) {
result[combinedKey].push(value);
} else {
result[combinedKey] = [value];
}
});
console.log(result);
const list = document.querySelectorAll('.elem');
let pool = [...list];
let counter = 0;
animate();
function animate(index = 0) {
setTimeout(() => {
if (!pool.length) {
pool = [...list];
counter = 0;
}
const current = pool.shift();
list[index - 1] && (list[index - 1].style.backgroundColor = 'white');
current.style.backgroundColor = 'red';
animate(++counter);
}, 1000);
}
<button id="sort" type="button">Sort</button>
<br><br>
<div id="body">
<div class="listing-item" data-event-date="2017-05-02">2017-05-02</div>
<div class="listing-item" data-event-date="2018-01-07">2018-01-07</div>
<div class="listing-item" data-event-date="2017-06-05">2017-06-05</div>
<div class="listing-item" data-event-date="2018-01-03">2018-01-03</div>
<div class="listing-item" data-event-date="2017-08-08">2017-08-08</div>
</div>
const items = [...document.querySelectorAll('.listing-item')];
function compare(a, b) {
const aData = new Date($(a).data('event-date'));
const bData = new Date($(b).data('event-date'));
if (aData < bData) {
return -1;
}
if (aData > bData) {
return 1;
}
return 0;
}
$('#sort').on('click', () => {
items.sort(compare);
$('#body').empty();
items.forEach(item => {
$('#body').append(item);
});
});
owl-carousel - там, вроде как, нельзя добавить миниатюры, хотя слайдер замечательный
$(document).on({
click: function(){
/* code */
}
}, '.block');
Проблема: не хочется вкорячивать код работающий с логгером и с бд в код бизнес-сущности
function foo() {
return {
save: function() {
return true;
}
};
}
foo().save(); // true
class Foo {
constructor() {}
someMethod() {
return this;
}
anotherMethod() {
return this;
}
save() {
return this;
}
}
var obj = new Foo();
obj.someMethod().anotherMethod().save().someMethod().anotherMethod().save();