【发布时间】:2020-03-30 09:17:23
【问题描述】:
我想比较对象(图像)和跨度标记(图像)的数组。在按钮上单击我需要检查丢弃的图像和跨度图像是否相等。请帮我解决这个问题。
component.html:
<div class="field-box-samp">
<div class="captchaText">
<span id="circle_text"><img src="https://www.gstatic.com/webp/galler/1.png"></span>
<span id="triangle_text"><img src="https://www.gstatic.com/webp/galler/2.png"></span>
<span id="square_text"><img src="https://www.gstatic.com/webp/galler/3.png"></span>
</div>
</div>
component.ts:
origin = [{
img: 'https://www.gstatic.com/webp/gallery3/1.png'
},
{
img: 'https://www.gstatic.com/webp/gallery3/2.png'
},
{
img: 'https://www.gstatic.com/webp/gallery3/3.png'
}];
//---------------
destination = [
];
//---------------
drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
let item:any = event.previousContainer.data[event.previousIndex];
let copy:any = JSON.parse(JSON.stringify(item));
let element:any = {};
for(let attr in copy){
if(attr == 'title'){
element[attr] = copy[attr] += ' copy';
}else{
element[attr] = copy[attr];
}
}
this.destination=[element];
clearimg()
}
}
}
【问题讨论】:
-
您能说得更具体些吗?你想比较什么?您想知道数组中的图像是否已经存在于 DOM 中吗?
标签: javascript arrays angular typescript object