HM-56. Добавлена страница для просмотра логов с фильтрацией, пагинацией (#20)
This commit is contained in:
34
src/utils/elementUtils.js
Normal file
34
src/utils/elementUtils.js
Normal file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @interface CreateElementProps
|
||||
* @type {Object}
|
||||
* @property {string} tagName - имя создаваемого тега
|
||||
* @property {Node} parentNode - родительский Node в который поместить элемент
|
||||
* @property {Object<string, string>} options - опции, которые можно присвоить объекту
|
||||
* @property {Object<string, string>} args - аргументы, которые нужно прикрепить к Node
|
||||
*/
|
||||
|
||||
/**
|
||||
* Функция создания элементов
|
||||
* @function createElement
|
||||
* @param {CreateElementProps} createElementProps - параметры для функции
|
||||
* @returns {Node}
|
||||
*/
|
||||
export const createElement = (createElementProps) => {
|
||||
const {tagName, parentNode, options, args} = createElementProps;
|
||||
const element = document.createElement(tagName);
|
||||
if (options) {
|
||||
Object.entries(options)
|
||||
.forEach(([key, value]) => {
|
||||
element[key] = value;
|
||||
});
|
||||
}
|
||||
|
||||
if (args) {
|
||||
Object.entries(args)
|
||||
.forEach(([attr, value]) => {
|
||||
element.setAttribute(attr, value);
|
||||
});
|
||||
}
|
||||
parentNode.appendChild(element);
|
||||
return element;
|
||||
};
|
||||
Reference in New Issue
Block a user