const { selectedButton } = this.state;
var boundingBoxCollection = [];
console.log(boundingBoxCollection.length);
var boundingBoxes = document.querySelectorAll('.cropper-face');
console.log("I am ice"+boundingBoxes.length);
if(boundingBoxes.length > 0){
boundingBoxes.forEach(elem => {
if(!boundingBoxCollection.includes(elem)){
boundingBoxCollection.push(elem);
}
});
}
我的boundingBoxCollection未更新
解决这个问题,我希望更新我的数组
const { selectedButton } = this.state;
// Ensure boundingBoxCollection is initialized properly
var boundingBoxCollection = Array.from(document.querySelectorAll('.cropper-face'));
console.log("Initial length: " + boundingBoxCollection.length);
// Loop through the selected elements and push them into boundingBoxCollection
var boundingBoxes = document.querySelectorAll('.cropper-face');
console.log("I am ice" + boundingBoxes.length);
if (boundingBoxes.length > 0) {
boundingBoxes.forEach(elem => {
if (!boundingBoxCollection.includes(elem)) {
boundingBoxCollection.push(elem);
}
});
}