我有一个基于 Select 图像的问题. 我有一个来自BE的对象数组,每个对象都有自己的坐标,这取决于图像的X和Y. IMAGE在那里有一些吸引力,并包括一些数字. 所以Obj上的属性itemNumber与img中显示的数字相同. 例如,如果itemNumber为1,则坐标为数字1将在图像上加边框.
到目前为止,我已经取得了一些成就,但我不能每次都 Select 正确的X和Y.
我创造了一个Stackblitz
在堆叠闪电战中,你可以找到2个IMG. 在第二个问题上,你会看到事情的本来面目. 我try 了很多方法,但都不成功
这是我的奥比杰儿子.
[
{
"itemNumber": "1",
"partNumber": "4400535240",
"coordinates": [
{
"itemCounter": 0,
"xposition": 970,
"yposition": 375
}
]
},
{
"itemNumber": "2",
"partNumber": "4400541680",
"coordinates": [
{
"itemCounter": 0,
"xposition": 1282,
"yposition": 522
}
]
},
{
"itemNumber": "4",
"partNumber": "4400541390",
"coordinates": [
{
"itemCounter": 0,
"xposition": 445,
"yposition": 307
}
]
},
]`
这是我的TS代码.
showCorner(event: ResponseList) {
console.log(event.coordinates)
const xClientHeight = document.getElementById('imgPath')?.clientHeight as number;
const xClientWidth = document.getElementById('imgPath')?.clientWidth as number;
console.log(xClientHeight);
console.log(xClientWidth);
this.coordinateX = xClientWidth - event.coordinates[0].yposition;
this.coordinateY = xClientHeight - event.coordinates[0].xposition;
(document.getElementById('rec1') as HTMLInputElement).innerHTML = "<img src='../../../assets/rec.gif' style='width:25px; height:25px;'></img>";
}
showImage(imagePath: string) {
return this.environment.endpoints.backendBaseUrl + imagePath; //
imagePath
}
我的HTML码
<table>
<thead>
<tr>
<th scope="col">Name</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of jsonData">
<td (click)="showCorner(row)">{{ row.name }}</td>
</tr>
</tbody>
</table>
<div class="flex-1 relative">
<div class="relative">
<img id="imgPath" (click.double)="addBorder($event)" style="width: 832px; max-width: fit-content;" [src]="showImage(partListImage.imagePath)">
<div id="rec1" class="absolute" [style]="{'left': coordinateX+ 'px', 'top': coordinateY+ 'px'}">
</div>
</div>
</div>
正如你在图像中看到的,其中有数字. 当您点击表格时,每个数字都将被选中.