【发布时间】:2019-10-19 22:33:48
【问题描述】:
我有一个表,其值来自 json 包含一些列。当您单击编辑按钮时,将打开一个框,其中复选框值将来自其他 json(statusdata),直到现在问题都很好被选中将基于点击行的状态列值,关闭框点击关闭链接,这里是下面的代码https://stackblitz.com/edit/angular-zqswrw
app.component.html
<table class="table border">
<thead>
<tr>
<ng-container *ngFor="let column of columns; let i = index">
<th>{{ column }}</th>
</ng-container>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of groups;let i = index">
<td>{{row.name}}</td>
<td>{{row.items}}</td>
<td >
<span class="status" *ngFor="let item of row.Status ;let j = index">
{{item.name}}
</span> <span *ngIf = "i == hoverIndex" class="hover-details"></span>
</td>
<td style="cursor:pointer;" (click)="edit(row);">Edit</td>
</tr>
</tbody>
</table>
<div style="border: 1px solid #000;
padding: 10px;
display: flex;
width: 100%;
margin-top: 1%;" *ngIf="block">
Status-checkbox:<div style="float:left" *ngFor="let status of statusdata">
<input type="checkbox" [checked]="" value="status.id" />{{status.name}}
</div>
<div (click)="close();" style="cursor:pointer;float:right;margin-left:10%;">close</div>
</div>
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
dotsh:any;
hoverIndex:number = -1;
groups:any;
test:any;
statusdata:any;
block:any;
closeit:any;
onHover(i:number){
this.hoverIndex = i;
}
columns = ["name", "Items","status","Action"];
edit(dataItem){
console.log(dataItem.status);
this.block = true;
}
ngOnInit() {
this.closeit = true;
this.block = false;
this.test = false;
this.groups=[{"id":1,"name":"pencils","items":"red pencil","Status":[{"id":1,"name":"green"},{"id":2,"name":"red"},{"id":3,"name":"yellow"}],"loc":[{"id":1,"name":"loc 1"},{"id":2,"name":"loc 2"},{"id":3,"name":"loc 3"}]},{"id":2,"name":"rubbers","items":"big rubber","Status":[{"id":1,"name":"green"},{"id":2,"name":"red"}],"loc":[{"id":1,"name":"loc 2"},{"id":2,"name":"loc 3"}]},{"id":3,"name":"rubbers1","items":"big rubber1","Status":[{"id":1,"name":"green"}],"loc":[{"id":1,"name":"loc 2"},{"id":2,"name":"loc 3"}]}];
this.statusdata = [{"id":1,"name":"green"},{"id":2,"name":"red"},{"id":3,"name":"yellow"}];
}
close(){
this.block = false;
}
}
【问题讨论】:
标签: html css angular typescript