Answer the question
In order to leave comments, you need to log in
How to find blocks?
I get a list of blocks like this:
let DOMBlocks = document.getElementsByClassName('obj-block'); // получаю блоки
let StoreBlock = this.blocks; // массив блоков
// Вот так выглядят блоки в сторе:
blocks: [{
id: 1,
position: {
top: 1,
left: 10
}
},
{
id: 2,
position: {
top: 200,
left: 350
}
}
]
// блоки рендерятся в следующее:
<div :class="'block obj-block block-' + block.id">
</div>
let DOMBlocks = document.getElementsByClassName('obj-block');
let StoreBlock = this.blocks;
let blocks = [];
for (let i = 0; i < DOMBlocks.length; i++){
console.log(DOMBlocks[i].className);
}
// и как их правильно добавлять в массив блоков, чтобы получилось это:
blocks = [
{
id: 1,
position: {},
...,
elementInDOM: DOMBlocks[i]
]
Answer the question
In order to leave comments, you need to log in
blocks.push({
id: /block-(\d+)/.exec(DOMBlocks[i].className)[1] * 1,
...
});
<div :class="'block obj-block'" :data-id="block.id">
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question