对了,现在我有了这段代码来绘制一些div(根据一些逻辑,我会有Parent和Childs.
array.forEach(async (a, b) => {
var currentDiv = 0;
let divHtml;
if (b === 0) {
//This should be the first parent
divHtml = document.createElement('div');
divHtml.id = 'someID' + currentDiv;
} else if (previousDiv != currentDiv) {
// This should be used for next parents based on the previousDiv & currentDiv logic
divHtml = document.createElement('div');
divHtml.id = 'someID' + currentDiv;
} else {
// This should be used only for childs. I want to create another div but inside the parent that I have stored into currentDiv.
divHtml = document.getElementById('someID' + currentDiv);
divHtml.id = 'someChildID' + currentDiv;
}
// Some more code below but what it's important is this (I continue using the divHtml in a lot of places on my code):
divHtml.setAttribute('someData', someDataAttribute);
});
所以,我的问题是:如果有一种方法可以获取parentDiv并在X Childs元素中绘制,我该如何做?我试过这样做:
divHtml = document.createElement('div').appendTo($('#someID' + currentDiv));
但我收到了.appendTo() is not a function错误消息.